Don't handle unitless length quirk in CSS parser fast path
This patch makes the CSS parser fast path reject unitless length (aside
from 0 and presentational svg attributes). The quirks mode spec allows
unitless lengths on a fixed set of CSS properties, which we correctly
handle inside the (full) property parser. Currently we will allow any
unitless lengths for any fast path length property when quirks mode is
enabled, instead of the smaller set where it is supposed to apply.
As quirks-mode is not a common case, we just don't support the unitless
length quirk at all in the fast path.
This patch also extends the property-parsing-test helper to allow for
quirks-mode-only values (which are rejected by CSS.supports) and also
fixes the test description for properties with hyphens.
https://quirks.spec.whatwg.org/#the-unitless-length-quirk
BUG=436145
Review URL: https://codereview.chromium.org/1475903002
Cr-Commit-Position: refs/heads/master@{#361619}
diff --git a/third_party/WebKit/LayoutTests/css-parser/resources/property-parsing-test.js b/third_party/WebKit/LayoutTests/css-parser/resources/property-parsing-test.js
index d0a9db3..109bbcd 100644
--- a/third_party/WebKit/LayoutTests/css-parser/resources/property-parsing-test.js
+++ b/third_party/WebKit/LayoutTests/css-parser/resources/property-parsing-test.js
@@ -12,15 +12,19 @@
});
}
-function assert_valid_value(property, value, serializedValue) {
- if (arguments.length != 3)
+function assert_valid_value(property, value, serializedValue, quirksModeOnly) {
+ if (arguments.length < 4)
+ quirksModeOnly = false;
+
+ if (arguments.length < 3)
serializedValue = value;
stringifiedValue = JSON.stringify(value);
+ dashedProperty = convert_to_dashes(property);
test(function(){
- assert_true(CSS.supports(convert_to_dashes(property), value));
- }, "CSS.supports('" + property + "', " + stringifiedValue + ") should return true");
+ assert_equals(!quirksModeOnly, CSS.supports(dashedProperty, value));
+ }, "CSS.supports('" + dashedProperty + "', " + stringifiedValue + ") should return " + !quirksModeOnly);
test(function(){
var div = document.createElement('div');
@@ -40,10 +44,11 @@
function assert_invalid_value(property, value) {
stringifiedValue = JSON.stringify(value);
+ dashedProperty = convert_to_dashes(property);
test(function(){
- assert_false(CSS.supports(convert_to_dashes(property), value));
- }, "CSS.supports('" + property + "', " + stringifiedValue + ") should return false");
+ assert_false(CSS.supports(dashedProperty, value));
+ }, "CSS.supports('" + dashedProperty + "', " + stringifiedValue + ") should return false");
test(function(){
var div = document.createElement('div');
diff --git a/third_party/WebKit/LayoutTests/css-parser/unitless-length-quirk.html b/third_party/WebKit/LayoutTests/css-parser/unitless-length-quirk.html
new file mode 100644
index 0000000..bca45b8
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/css-parser/unitless-length-quirk.html
@@ -0,0 +1,12 @@
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+<script src="resources/property-parsing-test.js"></script>
+<script>
+// Intentionally testing in quirks mode
+assert_valid_value("paddingLeft", "20", "20px", true);
+assert_valid_value("top", "30", "30px", true);
+assert_valid_value("minWidth", "40", "40px", true);
+
+assert_invalid_value("outlineWidth", "50");
+assert_invalid_value("motionOffset", "60");
+</script>
diff --git a/third_party/WebKit/Source/core/css/parser/CSSParserFastPaths.cpp b/third_party/WebKit/Source/core/css/parser/CSSParserFastPaths.cpp
index e799dbb0..e16992d 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSParserFastPaths.cpp
+++ b/third_party/WebKit/Source/core/css/parser/CSSParserFastPaths.cpp
@@ -109,15 +109,14 @@
}
if (unit == CSSPrimitiveValue::UnitType::Number) {
- bool quirksMode = isQuirksModeBehavior(cssParserMode);
- bool svgMode = cssParserMode == SVGAttributeMode;
- if (number && (!quirksMode && !svgMode))
- return nullptr;
- if (svgMode)
+ if (cssParserMode == SVGAttributeMode)
unit = CSSPrimitiveValue::UnitType::UserUnits;
- else
+ else if (!number)
unit = CSSPrimitiveValue::UnitType::Pixels;
+ else
+ return nullptr;
}
+
if (number < 0 && !acceptsNegativeNumbers)
return nullptr;