Changeset 279429 in webkit


Ignore:
Timestamp:
Jun 30, 2021 1:07:25 PM (13 months ago)
Author:
Darin Adler
Message:

CSS specification prohibits numbers with trailing decimal point (e.g. "1.px"), but we allow them
https://bugs.webkit.org/show_bug.cgi?id=227517

Reviewed by Sam Weinig.

LayoutTests/imported/w3c:

  • web-platform-tests/css/css-syntax/decimal-points-in-numbers-expected.txt:

Expect a pass instead of a fail.

Source/WebCore:

Test: imported/w3c/web-platform-tests/css/css-syntax/decimal-points-in-numbers.html

  • css/parser/CSSParserFastPaths.cpp:

(WebCore::parseCSSNumber): Added. Checks for the trailing decimal point. Also uses
std::optional instead of a bool plus an out argument; should refactor the other functions
to work that way at some point.
(WebCore::parseSimpleLength): Use parseCSSNumber and isASCIIAlphaCaselessEqual.
(WebCore::parseSimpleAngle): Ditto.
(WebCore::parseTransformNumberArguments): Ditto.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r279427 r279429  
     12021-06-30  Darin Adler  <darin@apple.com>
     2
     3        CSS specification prohibits numbers with trailing decimal point (e.g. "1.px"), but we allow them
     4        https://bugs.webkit.org/show_bug.cgi?id=227517
     5
     6        Reviewed by Sam Weinig.
     7
     8        * web-platform-tests/css/css-syntax/decimal-points-in-numbers-expected.txt:
     9        Expect a pass instead of a fail.
     10
    1112021-06-30  Chris Dumez  <cdumez@apple.com>
    212
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-syntax/decimal-points-in-numbers-expected.txt

    r267650 r279429  
    55PASS decimal point between digits is valid in a dimension
    66PASS decimal point before digits is valid in a dimension
    7 FAIL decimal point after digits is invalid in a dimension assert_not_equals: got disallowed value "1px"
     7PASS decimal point after digits is invalid in a dimension
    88
  • trunk/Source/WebCore/ChangeLog

    r279424 r279429  
     12021-06-30  Darin Adler  <darin@apple.com>
     2
     3        CSS specification prohibits numbers with trailing decimal point (e.g. "1.px"), but we allow them
     4        https://bugs.webkit.org/show_bug.cgi?id=227517
     5
     6        Reviewed by Sam Weinig.
     7
     8        Test: imported/w3c/web-platform-tests/css/css-syntax/decimal-points-in-numbers.html
     9
     10        * css/parser/CSSParserFastPaths.cpp:
     11        (WebCore::parseCSSNumber): Added. Checks for the trailing decimal point. Also uses
     12        std::optional instead of a bool plus an out argument; should refactor the other functions
     13        to work that way at some point.
     14        (WebCore::parseSimpleLength): Use parseCSSNumber and isASCIIAlphaCaselessEqual.
     15        (WebCore::parseSimpleAngle): Ditto.
     16        (WebCore::parseTransformNumberArguments): Ditto.
     17
    1182021-06-30  Kimmo Kinnunen  <kkinnunen@apple.com>
    219
  • trunk/Source/WebCore/css/parser/CSSParserFastPaths.cpp

    r278253 r279429  
    100100}
    101101
     102template<typename CharacterType> static inline std::optional<double> parseCSSNumber(const CharacterType* characters, unsigned length)
     103{
     104    // The charactersToDouble() function allows a trailing '.' but that is not allowed in CSS number values.
     105    if (length && characters[length - 1] == '.')
     106        return std::nullopt;
     107    // FIXME: If we don't want to skip over leading spaces, we should use parseDouble, not charactersToDouble.
     108    bool ok;
     109    auto number = charactersToDouble(characters, length, &ok);
     110    if (!ok)
     111        return std::nullopt;
     112    return number;
     113}
     114
    102115template <typename CharacterType>
    103116static inline bool parseSimpleLength(const CharacterType* characters, unsigned length, CSSUnitType& unit, double& number)
    104117{
    105     if (length > 2 && (characters[length - 2] | 0x20) == 'p' && (characters[length - 1] | 0x20) == 'x') {
     118    if (length > 2 && isASCIIAlphaCaselessEqual(characters[length - 2], 'p') && isASCIIAlphaCaselessEqual(characters[length - 1], 'x')) {
    106119        length -= 2;
    107120        unit = CSSUnitType::CSS_PX;
     
    111124    }
    112125
    113     // We rely on charactersToDouble for validation as well. The function
    114     // will set "ok" to "false" if the entire passed-in character range does
    115     // not represent a double.
    116     bool ok;
    117     number = charactersToDouble(characters, length, &ok);
    118     if (!ok)
    119         return false;
    120     return true;
     126    auto parsedNumber = parseCSSNumber(characters, length);
     127    number = parsedNumber.value_or(0);
     128    return parsedNumber.has_value();
    121129}
    122130
     
    128136        return false;
    129137
    130     if ((characters[length - 3] | 0x20) == 'd' && (characters[length - 2] | 0x20) == 'e' && (characters[length - 1] | 0x20) == 'g') {
     138    if (isASCIIAlphaCaselessEqual(characters[length - 3], 'd') && isASCIIAlphaCaselessEqual(characters[length - 2], 'e') && isASCIIAlphaCaselessEqual(characters[length - 1], 'g')) {
    131139        length -= 3;
    132140        unit = CSSUnitType::CSS_DEG;
    133     } else if ((characters[length - 3] | 0x20) == 'r' && (characters[length - 2] | 0x20) == 'a' && (characters[length - 1] | 0x20) == 'd') {
     141    } else if (isASCIIAlphaCaselessEqual(characters[length - 3], 'r') && isASCIIAlphaCaselessEqual(characters[length - 2], 'a') && isASCIIAlphaCaselessEqual(characters[length - 1], 'd')) {
    134142        length -= 3;
    135143        unit = CSSUnitType::CSS_RAD;
     
    137145        return false;
    138146
    139     // We rely on charactersToDouble for validation as well. The function
    140     // will set "ok" to "false" if the entire passed-in character range does
    141     // not represent a double.
    142     bool ok;
    143     number = charactersToDouble(characters, length, &ok);
    144     if (!ok)
    145         return false;
    146     return true;
     147    auto parsedNumber = parseCSSNumber(characters, length);
     148    number = parsedNumber.value_or(0);
     149    return parsedNumber.has_value();
    147150}
    148151
     
    11691172            return false;
    11701173        unsigned argumentLength = static_cast<unsigned>(delimiter);
    1171         bool ok;
    1172         double number = charactersToDouble(pos, argumentLength, &ok);
    1173         if (!ok)
     1174        auto number = parseCSSNumber(pos, argumentLength);
     1175        if (!number)
    11741176            return false;
    1175         transformValue->append(CSSPrimitiveValue::create(number, CSSUnitType::CSS_NUMBER));
     1177        transformValue->append(CSSPrimitiveValue::create(*number, CSSUnitType::CSS_NUMBER));
    11761178        pos += argumentLength + 1;
    11771179        --expectedCount;
Note: See TracChangeset for help on using the changeset viewer.