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

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: Patch for landing 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
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/css/parsing-color-quirk.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 49b1abb42138a4ef1369528973876cc8971d16e8..3d678d73a50c6ba9d7abf3f442380782b632241d 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.cpp
+++ b/third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.cpp
@@ -405,14 +405,14 @@ 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
- 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.type() == NumberToken || token.type() == DimensionToken) {
+ if (token.numericValueType() != IntegerValueType
+ || token.numericValue() < 0. || token.numericValue() >= 1000000.)
return false;
+ if (token.type() == NumberToken) // e.g. 112233
+ color = String::format("%d", static_cast<int>(token.numericValue()));
+ else // e.g. 0001FF
+ color = String::number(static_cast<int>(token.numericValue())) + String(token.value());
while (color.length() < 6)
color = "0" + color;
} else if (token.type() == IdentToken) { // e.g. FF0000
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/css/parsing-color-quirk.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698