Modified: trunk/LayoutTests/imported/w3c/ChangeLog (279428 => 279429)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2021-06-30 19:48:47 UTC (rev 279428)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2021-06-30 20:07:25 UTC (rev 279429)
@@ -1,3 +1,13 @@
+2021-06-30 Darin Adler <[email protected]>
+
+ 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.
+
+ * web-platform-tests/css/css-syntax/decimal-points-in-numbers-expected.txt:
+ Expect a pass instead of a fail.
+
2021-06-30 Chris Dumez <[email protected]>
Resync html WPT tests from upstream
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-syntax/decimal-points-in-numbers-expected.txt (279428 => 279429)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-syntax/decimal-points-in-numbers-expected.txt 2021-06-30 19:48:47 UTC (rev 279428)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-syntax/decimal-points-in-numbers-expected.txt 2021-06-30 20:07:25 UTC (rev 279429)
@@ -4,5 +4,5 @@
PASS decimal point after digits is invalid in a number
PASS decimal point between digits is valid in a dimension
PASS decimal point before digits is valid in a dimension
-FAIL decimal point after digits is invalid in a dimension assert_not_equals: got disallowed value "1px"
+PASS decimal point after digits is invalid in a dimension
Modified: trunk/Source/WebCore/ChangeLog (279428 => 279429)
--- trunk/Source/WebCore/ChangeLog 2021-06-30 19:48:47 UTC (rev 279428)
+++ trunk/Source/WebCore/ChangeLog 2021-06-30 20:07:25 UTC (rev 279429)
@@ -1,3 +1,20 @@
+2021-06-30 Darin Adler <[email protected]>
+
+ 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.
+
+ 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.
+
2021-06-30 Kimmo Kinnunen <[email protected]>
toDataURL image upside down if premultipliedAlpha=false
Modified: trunk/Source/WebCore/css/parser/CSSParserFastPaths.cpp (279428 => 279429)
--- trunk/Source/WebCore/css/parser/CSSParserFastPaths.cpp 2021-06-30 19:48:47 UTC (rev 279428)
+++ trunk/Source/WebCore/css/parser/CSSParserFastPaths.cpp 2021-06-30 20:07:25 UTC (rev 279429)
@@ -99,10 +99,23 @@
}
}
+template<typename CharacterType> static inline std::optional<double> parseCSSNumber(const CharacterType* characters, unsigned length)
+{
+ // The charactersToDouble() function allows a trailing '.' but that is not allowed in CSS number values.
+ if (length && characters[length - 1] == '.')
+ return std::nullopt;
+ // FIXME: If we don't want to skip over leading spaces, we should use parseDouble, not charactersToDouble.
+ bool ok;
+ auto number = charactersToDouble(characters, length, &ok);
+ if (!ok)
+ return std::nullopt;
+ return number;
+}
+
template <typename CharacterType>
static inline bool parseSimpleLength(const CharacterType* characters, unsigned length, CSSUnitType& unit, double& number)
{
- if (length > 2 && (characters[length - 2] | 0x20) == 'p' && (characters[length - 1] | 0x20) == 'x') {
+ if (length > 2 && isASCIIAlphaCaselessEqual(characters[length - 2], 'p') && isASCIIAlphaCaselessEqual(characters[length - 1], 'x')) {
length -= 2;
unit = CSSUnitType::CSS_PX;
} else if (length > 1 && characters[length - 1] == '%') {
@@ -110,14 +123,9 @@
unit = CSSUnitType::CSS_PERCENTAGE;
}
- // We rely on charactersToDouble for validation as well. The function
- // will set "ok" to "false" if the entire passed-in character range does
- // not represent a double.
- bool ok;
- number = charactersToDouble(characters, length, &ok);
- if (!ok)
- return false;
- return true;
+ auto parsedNumber = parseCSSNumber(characters, length);
+ number = parsedNumber.value_or(0);
+ return parsedNumber.has_value();
}
template <typename CharacterType>
@@ -127,23 +135,18 @@
if (length < 4)
return false;
- if ((characters[length - 3] | 0x20) == 'd' && (characters[length - 2] | 0x20) == 'e' && (characters[length - 1] | 0x20) == 'g') {
+ if (isASCIIAlphaCaselessEqual(characters[length - 3], 'd') && isASCIIAlphaCaselessEqual(characters[length - 2], 'e') && isASCIIAlphaCaselessEqual(characters[length - 1], 'g')) {
length -= 3;
unit = CSSUnitType::CSS_DEG;
- } else if ((characters[length - 3] | 0x20) == 'r' && (characters[length - 2] | 0x20) == 'a' && (characters[length - 1] | 0x20) == 'd') {
+ } else if (isASCIIAlphaCaselessEqual(characters[length - 3], 'r') && isASCIIAlphaCaselessEqual(characters[length - 2], 'a') && isASCIIAlphaCaselessEqual(characters[length - 1], 'd')) {
length -= 3;
unit = CSSUnitType::CSS_RAD;
} else
return false;
- // We rely on charactersToDouble for validation as well. The function
- // will set "ok" to "false" if the entire passed-in character range does
- // not represent a double.
- bool ok;
- number = charactersToDouble(characters, length, &ok);
- if (!ok)
- return false;
- return true;
+ auto parsedNumber = parseCSSNumber(characters, length);
+ number = parsedNumber.value_or(0);
+ return parsedNumber.has_value();
}
static RefPtr<CSSValue> parseSimpleLengthValue(CSSPropertyID propertyId, StringView string, CSSParserMode cssParserMode)
@@ -1168,11 +1171,10 @@
if (delimiter == notFound)
return false;
unsigned argumentLength = static_cast<unsigned>(delimiter);
- bool ok;
- double number = charactersToDouble(pos, argumentLength, &ok);
- if (!ok)
+ auto number = parseCSSNumber(pos, argumentLength);
+ if (!number)
return false;
- transformValue->append(CSSPrimitiveValue::create(number, CSSUnitType::CSS_NUMBER));
+ transformValue->append(CSSPrimitiveValue::create(*number, CSSUnitType::CSS_NUMBER));
pos += argumentLength + 1;
--expectedCount;
}