Commit b3c62041 authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

[css-typed-om] Ignore surrounding whitespace in CSSNumericValue.parse.

Fixes an issue where CSSNumericValue.parse considers valid strings
surrounded by whitespace to be invalid.

Bug: 844290
Change-Id: I4c40044631276a611ef9a56aac21ddf09316a550
Reviewed-on: https://chromium-review.googlesource.com/1065532Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560207}
parent 21070080
...@@ -23,4 +23,8 @@ test(() => { ...@@ -23,4 +23,8 @@ test(() => {
assert_throws(new SyntaxError(), () => CSSNumericValue.parse('calc(calc(1px * 2s) + 3%)')); assert_throws(new SyntaxError(), () => CSSNumericValue.parse('calc(calc(1px * 2s) + 3%)'));
}, 'Parsing a calc with incompatible units throws a SyntaxError'); }, 'Parsing a calc with incompatible units throws a SyntaxError');
test(() => {
assert_style_value_equals(new CSSUnitValue(1, 'px'), CSSNumericValue.parse(' 1px '));
}, 'Parsing ignores surrounding spaces');
</script> </script>
...@@ -205,7 +205,9 @@ CSSNumericValue* CSSNumericValue::parse(const String& css_text, ...@@ -205,7 +205,9 @@ CSSNumericValue* CSSNumericValue::parse(const String& css_text,
ExceptionState& exception_state) { ExceptionState& exception_state) {
CSSTokenizer tokenizer(css_text); CSSTokenizer tokenizer(css_text);
CSSParserTokenStream stream(tokenizer); CSSParserTokenStream stream(tokenizer);
stream.ConsumeWhitespace();
auto range = stream.ConsumeUntilPeekedTypeIs<>(); auto range = stream.ConsumeUntilPeekedTypeIs<>();
stream.ConsumeWhitespace();
if (!stream.AtEnd()) { if (!stream.AtEnd()) {
exception_state.ThrowDOMException(kSyntaxError, "Invalid math expression"); exception_state.ThrowDOMException(kSyntaxError, "Invalid math expression");
return nullptr; return nullptr;
...@@ -215,7 +217,7 @@ CSSNumericValue* CSSNumericValue::parse(const String& css_text, ...@@ -215,7 +217,7 @@ CSSNumericValue* CSSNumericValue::parse(const String& css_text,
case kNumberToken: case kNumberToken:
case kPercentageToken: case kPercentageToken:
case kDimensionToken: { case kDimensionToken: {
const auto token = range.Consume(); const auto token = range.ConsumeIncludingWhitespace();
if (!range.AtEnd()) if (!range.AtEnd())
break; break;
return CSSUnitValue::Create(token.NumericValue(), token.GetUnitType()); return CSSUnitValue::Create(token.NumericValue(), token.GetUnitType());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment