Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Unified Diff: third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.cpp

Issue 1963843002: Implement stricter hashless hex color parsing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add more subtests Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.cpp
diff --git a/third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.cpp b/third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.cpp
index 0fe218a71e5f9fa77ac5318125288cde0d22eb9b..c3ca48ea02f0b913be52904e7869d448040e256b 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.cpp
+++ b/third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.cpp
@@ -405,14 +405,15 @@ static bool parseHexColor(CSSParserTokenRange& range, RGBA32& result, bool accep
const CSSParserToken& token = range.peek();
String color;
if (acceptQuirkyColors) {
- if (token.type() == NumberToken && token.numericValueType() == IntegerValueType
- && token.numericValue() >= 0. && token.numericValue() < 1000000.) { // e.g. 112233
+ if (token.type() == NumberToken) { // e.g. 112233
+ if (token.numericValueType() != IntegerValueType
+ || token.numericValue() < 0. || token.numericValue() >= 1000000.)
+ return false;
color = String::format("%06d", static_cast<int>(token.numericValue()));
} else if (token.type() == DimensionToken) { // e.g. 0001FF
- // TODO(timloh): This should check the numericValueType flag
- color = String::number(static_cast<int>(token.numericValue())) + String(token.value());
- if (color.length() > 6)
+ if (token.numericValueType() != IntegerValueType || token.numericValue() < 0.)
return false;
+ color = String::number(static_cast<int>(token.numericValue())) + String(token.value());
rune 2016/05/10 21:27:32 What happens with the static_cast when numericValu
rwlbuis 2016/05/10 21:34:31 Good point! Will have a look.
while (color.length() < 6)
color = "0" + color;
} else if (token.type() == IdentToken) { // e.g. FF0000

Powered by Google App Engine
This is Rietveld 408576698