Skip to content

Commit

Permalink
Add <dimension-token> type-checking to CSSNumericValue::parse()
Browse files Browse the repository at this point in the history
This patch implements a recent spec bug fix:

w3c/css-houdini-drafts#1065

Fixed: 1291603
Change-Id: I3adae8148dd47b24d4516448e492daccce7ecd91
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3425673
Auto-Submit: Xiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: Anders Hartvoll Ruud <andruud@chromium.org>
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/main@{#965351}
  • Loading branch information
xiaochengh authored and Chromium LUCI CQ committed Jan 31, 2022
1 parent 665d211 commit 1e12a4f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ CSSNumericValue* CSSNumericValue::parse(const String& css_text,
case kPercentageToken:
case kDimensionToken: {
const auto token = range.ConsumeIncludingWhitespace();
if (!range.AtEnd())
if (!range.AtEnd() || !IsValidUnit(token.GetUnitType()))
break;
return CSSUnitValue::Create(token.NumericValue(), token.GetUnitType());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
assert_throws_dom("SyntaxError", () => CSSNumericValue.parse('calc(calc(1px * 2s) + 3%)'));
}, 'Parsing a calc with incompatible units throws a SyntaxError');

test(() => {
assert_throws_dom("SyntaxError", () => CSSNumericValue.parse('1xyz'));
}, 'Parsing a <dimension-token> with invalid units throws a SyntaxError');

test(() => {
assert_style_value_equals(new CSSUnitValue(1, 'px'), CSSNumericValue.parse(' 1px '));
}, 'Parsing ignores surrounding spaces');
Expand Down

0 comments on commit 1e12a4f

Please sign in to comment.