Index: third_party/WebKit/Source/core/html/HTMLElement.cpp |
diff --git a/third_party/WebKit/Source/core/html/HTMLElement.cpp b/third_party/WebKit/Source/core/html/HTMLElement.cpp |
index 6315b9278f5133ba3187559df498d20f6070aa9b..428b7c8a8c0610c1f390cf3332eb7f3a199ab1ad 100644 |
--- a/third_party/WebKit/Source/core/html/HTMLElement.cpp |
+++ b/third_party/WebKit/Source/core/html/HTMLElement.cpp |
@@ -925,12 +925,20 @@ void HTMLElement::addHTMLColorToStyle(MutableStylePropertySet* style, CSSPropert |
if (equalIgnoringCase(colorString, "transparent")) |
return; |
- // If the string is a named CSS color or a 3/6-digit hex color, use that. |
- Color parsedColor; |
- if (!parsedColor.setFromString(colorString)) |
- parsedColor.setRGB(parseColorStringWithCrazyLegacyRules(colorString)); |
+ Color color; |
- style->setProperty(propertyID, cssValuePool().createColorValue(parsedColor.rgb())); |
+ // If the string is a 3/6-digit hex color or a named CSS color, use that. Apply legacy rules otherwise. Note color.setFromString() |
+ // accepts 4/8-digit hex color, so restrict its use with length checks here to support legacy HTML attributes. |
+ |
+ bool success = false; |
+ if ((colorString.length() == 4 || colorString.length() == 7) && colorString[0] == '#') |
+ success = color.setFromString(colorString); |
+ if (!success) |
+ success = color.setNamedColor(colorString); |
+ if (!success) |
+ color.setRGB(parseColorStringWithCrazyLegacyRules(colorString)); |
+ |
+ style->setProperty(propertyID, cssValuePool().createColorValue(color.rgb())); |
} |
bool HTMLElement::isInteractiveContent() const |