Commit 759bba67 authored by junov's avatar junov Committed by Commit bot

Fix the parsing of colors used as canvas styles to ignore whitespace

BUG=668584

Review-Url: https://codereview.chromium.org/2560993003
Cr-Commit-Position: refs/heads/master@{#437710}
parent 2fc6cf8d
<!DOCTYPE html>
<title>Test whitespace parsing on canvas attributes that invoke the CSS parser</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
var ctx;
function whiteSpaceTest(attribute, input, output) {
var canvas = document.createElement('canvas');
ctx = canvas.getContext('2d');
eval('ctx.' + attribute + ' = "' + input + '"');
assert_equals(eval('ctx.' + attribute), output);
}
generate_tests(whiteSpaceTest, [
['', 'fillStyle', ' red', '#ff0000'],
['', 'fillStyle', 'red ', '#ff0000'],
['', 'fillStyle', '\tred', '#ff0000'],
['', 'fillStyle', 'red\t', '#ff0000'],
['', 'fillStyle', ' #f00', '#ff0000'],
['', 'fillStyle', '#f00 ', '#ff0000'],
['', 'fillStyle', '\t#f00', '#ff0000'],
['', 'fillStyle', '#f00\t', '#ff0000'],
['', 'fillStyle', ' rgb(255, 0, 0)', '#ff0000'],
['', 'fillStyle', 'rgb(255,0,0) ', '#ff0000'],
['', 'fillStyle', 'invalid', '#000000'], // Sanity check
['', 'strokeStyle', ' red', '#ff0000'],
['', 'strokeStyle', 'red ', '#ff0000'],
['', 'strokeStyle', '\tred', '#ff0000'],
['', 'strokeStyle', 'red\t', '#ff0000'],
['', 'strokeStyle', 'invalid', '#000000'], // Sanity check
// The filter attribute is different: it does not get re-serialized
['', 'filter', ' blur(5px)', ' blur(5px)'],
['', 'filter', 'blur(5px) ', 'blur(5px) '],
['', 'filter', 'blur( 5px)', 'blur( 5px)'],
['', 'filter', '\tblur(5px)', '\tblur(5px)'],
['', 'filter', 'blur(5px)\t', 'blur(5px)\t'],
['', 'filter', 'invalid', 'none'], // Sanity check
]);
</script>
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "core/css/StylePropertySet.h" #include "core/css/StylePropertySet.h"
#include "core/css/parser/CSSParser.h" #include "core/css/parser/CSSParser.h"
#include "core/html/HTMLCanvasElement.h" #include "core/html/HTMLCanvasElement.h"
#include "core/html/parser/HTMLParserIdioms.h"
#include "modules/canvas2d/CanvasGradient.h" #include "modules/canvas2d/CanvasGradient.h"
#include "modules/canvas2d/CanvasPattern.h" #include "modules/canvas2d/CanvasPattern.h"
#include "platform/graphics/skia/SkiaUtils.h" #include "platform/graphics/skia/SkiaUtils.h"
...@@ -71,7 +72,8 @@ static Color currentColor(HTMLCanvasElement* canvas) { ...@@ -71,7 +72,8 @@ static Color currentColor(HTMLCanvasElement* canvas) {
bool parseColorOrCurrentColor(Color& parsedColor, bool parseColorOrCurrentColor(Color& parsedColor,
const String& colorString, const String& colorString,
HTMLCanvasElement* canvas) { HTMLCanvasElement* canvas) {
ColorParseResult parseResult = parseColor(parsedColor, colorString); ColorParseResult parseResult =
parseColor(parsedColor, colorString.stripWhiteSpace(isHTMLSpace<UChar>));
switch (parseResult) { switch (parseResult) {
case ParsedRGBA: case ParsedRGBA:
case ParsedSystemColor: case ParsedSystemColor:
......
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