From d52f654a2cf1c67c86201d384193b48ca531bba4 Mon Sep 17 00:00:00 2001 From: Aaron Krajeski Date: Mon, 30 Jan 2023 13:39:32 -0800 Subject: [PATCH] Don't parse color functions with missing parameters. From ch..@w3.org: """ This used to be correct per spec, long ago when color() also did custom color spaces and it was reasonable to omit some components and have them auto-filled with zero. Now custom color spaces are in CSS Color 5, and clearly distinguished with a dashed-ident; while predefined color spaces are in CSS Color 4 and are wither an RGB space or an XYZ space. Both take 3 components, as the grammar makes clear. There was some leftover prose about variable number of components, not up to date with the grammar change, which I just corrected. """ Bug: 1410200 Change-Id: I6e1e7d49b91d91a1c61be95a837555f861a5478c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4198199 Reviewed-by: Rune Lillesveen Commit-Queue: Aaron Krajeski Cr-Commit-Position: refs/heads/main@{#1098869} --- .../parsing/color-computed-color-function.html | 15 --------------- .../parsing/color-invalid-color-function.html | 14 ++++++++++++++ .../parsing/color-valid-color-function.html | 12 ------------ 3 files changed, 14 insertions(+), 27 deletions(-) diff --git a/css/css-color/parsing/color-computed-color-function.html b/css/css-color/parsing/color-computed-color-function.html index e610754c644a4e..530a605bc9292f 100644 --- a/css/css-color/parsing/color-computed-color-function.html +++ b/css/css-color/parsing/color-computed-color-function.html @@ -31,12 +31,6 @@ test_computed_value("color", `color(${colorSpace} 0 0 0 / -10%)`, `color(${colorSpace} 0 0 0 / 0)`); test_computed_value("color", `color(${colorSpace} 0 0 0 / 110%)`, `color(${colorSpace} 0 0 0)`); test_computed_value("color", `color(${colorSpace} 0 0 0 / 300%)`, `color(${colorSpace} 0 0 0)`); - test_computed_value("color", `color(${colorSpace} 50% -200)`, `color(${colorSpace} 0.5 -200 0)`); - test_computed_value("color", `color(${colorSpace} 50%)`, `color(${colorSpace} 0.5 0 0)`); - test_computed_value("color", `color(${colorSpace})`, `color(${colorSpace} 0 0 0)`); - test_computed_value("color", `color(${colorSpace} 50% -200 / 0.5)`, `color(${colorSpace} 0.5 -200 0 / 0.5)`); - test_computed_value("color", `color(${colorSpace} 50% / 0.5)`, `color(${colorSpace} 0.5 0 0 / 0.5)`); - test_computed_value("color", `color(${colorSpace} / 0.5)`, `color(${colorSpace} 0 0 0 / 0.5)`); test_computed_value("color", `color(${colorSpace} 200 200 200)`, `color(${colorSpace} 200 200 200)`); test_computed_value("color", `color(${colorSpace} 200 200 200 / 200)`, `color(${colorSpace} 200 200 200)`); test_computed_value("color", `color(${colorSpace} -200 -200 -200)`, `color(${colorSpace} -200 -200 -200)`); @@ -71,12 +65,6 @@ test_computed_value("color", `color(${colorSpace} 0 0 0 / -10%)`, `color(${resultColorSpace} 0 0 0 / 0)`); test_computed_value("color", `color(${colorSpace} 0 0 0 / 110%)`, `color(${resultColorSpace} 0 0 0)`); test_computed_value("color", `color(${colorSpace} 0 0 0 / 300%)`, `color(${resultColorSpace} 0 0 0)`); - test_computed_value("color", `color(${colorSpace} 1 1)`, `color(${resultColorSpace} 1 1 0)`); - test_computed_value("color", `color(${colorSpace} 1)`, `color(${resultColorSpace} 1 0 0)`); - test_computed_value("color", `color(${colorSpace})`, `color(${resultColorSpace} 0 0 0)`); - test_computed_value("color", `color(${colorSpace} 1 1 / .5)`, `color(${resultColorSpace} 1 1 0 / 0.5)`); - test_computed_value("color", `color(${colorSpace} 1 / 0.5)`, `color(${resultColorSpace} 1 0 0 / 0.5)`); - test_computed_value("color", `color(${colorSpace} / 50%)`, `color(${resultColorSpace} 0 0 0 / 0.5)`); test_computed_value("color", `color(${colorSpace} calc(0.5 + 1) calc(0.5 - 1) calc(0.5) / calc(-0.5 + 1))`, `color(${resultColorSpace} 1.5 -0.5 0.5 / 0.5)`); test_computed_value("color", `color(${colorSpace} none none none / none)`, `color(${resultColorSpace} none none none / none)`); @@ -276,9 +264,6 @@ test_computed_value("color", "color(srgb 1 1 1 / 0)", "color(srgb 1 1 1 / 0)", "[sRGB white with 0 alpha]"); test_computed_value("color", "color(srgb 1 1 1 / 50%)", "color(srgb 1 1 1 / 0.5)", "[sRGB white with 50% alpha]"); test_computed_value("color", "color(srgb 1 1 1 / 0%)", "color(srgb 1 1 1 / 0)", "[sRGB white with 0% alpha]"); -test_computed_value("color", "color(srgb 1 1)", "color(srgb 1 1 0)", "[One missing component is 0]"); -test_computed_value("color", "color(srgb 1)", "color(srgb 1 0 0)", "[Two missing components are 0]"); -test_computed_value("color", "color(srgb)", "color(srgb 0 0 0)", "[All components missing]"); test_computed_value("color", "color(display-p3 0.6 0.7 0.8)", "color(display-p3 0.6 0.7 0.8)", "[Display P3 color]"); test_computed_value("color", "color(dIspLaY-P3 0.6 0.7 0.8)", "color(display-p3 0.6 0.7 0.8)", "[Different case for Display P3]"); diff --git a/css/css-color/parsing/color-invalid-color-function.html b/css/css-color/parsing/color-invalid-color-function.html index 75d9ff7c21764b..51f393747c19a2 100644 --- a/css/css-color/parsing/color-invalid-color-function.html +++ b/css/css-color/parsing/color-invalid-color-function.html @@ -20,6 +20,13 @@ test_invalid_value("color", `color(${colorSpace} 0% 0 0deg)`); test_invalid_value("color", `color(${colorSpace} 0% 0% 0deg)`); test_invalid_value("color", `color(${colorSpace} 40% 0 0deg)`); + // Missing parameters should not parse + test_invalid_value("color", `color(${colorSpace} 50% -200)`); + test_invalid_value("color", `color(${colorSpace} 50%)`); + test_invalid_value("color", `color(${colorSpace})`); + test_invalid_value("color", `color(${colorSpace} 50% -200 / 0.5)`); + test_invalid_value("color", `color(${colorSpace} 50% / 0.5)`); + test_invalid_value("color", `color(${colorSpace} / 0.5)`); } for (const colorSpace of [ "xyz", "xyz-d50", "xyz-d65" ]) { @@ -30,6 +37,13 @@ test_invalid_value("color", `color(${colorSpace} 0% 0 0deg)`); test_invalid_value("color", `color(${colorSpace} 0% 0% 0deg)`); test_invalid_value("color", `color(${colorSpace} 40% 0 0deg)`); + // Missing parameters should not parse + test_invalid_value("color", `color(${colorSpace} 1 1)`); + test_invalid_value("color", `color(${colorSpace} 1)`); + test_invalid_value("color", `color(${colorSpace})`); + test_invalid_value("color", `color(${colorSpace} 1 1 / .5)`); + test_invalid_value("color", `color(${colorSpace} 1 / 0.5)`); + test_invalid_value("color", `color(${colorSpace} / 50%)`); } test_invalid_value("color", "color()"); // Empty diff --git a/css/css-color/parsing/color-valid-color-function.html b/css/css-color/parsing/color-valid-color-function.html index 79e0bde059013d..1eb7c744b2acee 100644 --- a/css/css-color/parsing/color-valid-color-function.html +++ b/css/css-color/parsing/color-valid-color-function.html @@ -26,12 +26,6 @@ test_valid_value("color", `color(${colorSpace} 0 0 0 / -10%)`, `color(${colorSpace} 0 0 0 / 0)`); test_valid_value("color", `color(${colorSpace} 0 0 0 / 110%)`, `color(${colorSpace} 0 0 0)`); test_valid_value("color", `color(${colorSpace} 0 0 0 / 300%)`, `color(${colorSpace} 0 0 0)`); - test_valid_value("color", `color(${colorSpace} 50% -200)`, `color(${colorSpace} 0.5 -200 0)`); - test_valid_value("color", `color(${colorSpace} 50%)`, `color(${colorSpace} 0.5 0 0)`); - test_valid_value("color", `color(${colorSpace})`, `color(${colorSpace} 0 0 0)`); - test_valid_value("color", `color(${colorSpace} 50% -200 / 0.5)`, `color(${colorSpace} 0.5 -200 0 / 0.5)`); - test_valid_value("color", `color(${colorSpace} 50% / 0.5)`, `color(${colorSpace} 0.5 0 0 / 0.5)`); - test_valid_value("color", `color(${colorSpace} / 0.5)`, `color(${colorSpace} 0 0 0 / 0.5)`); test_valid_value("color", `color(${colorSpace} 200 200 200)`, `color(${colorSpace} 200 200 200)`); test_valid_value("color", `color(${colorSpace} 200 200 200 / 200)`, `color(${colorSpace} 200 200 200)`); test_valid_value("color", `color(${colorSpace} -200 -200 -200)`, `color(${colorSpace} -200 -200 -200)`); @@ -66,12 +60,6 @@ test_valid_value("color", `color(${colorSpace} 0 0 0 / -10%)`, `color(${resultColorSpace} 0 0 0 / 0)`); test_valid_value("color", `color(${colorSpace} 0 0 0 / 110%)`, `color(${resultColorSpace} 0 0 0)`); test_valid_value("color", `color(${colorSpace} 0 0 0 / 300%)`, `color(${resultColorSpace} 0 0 0)`); - test_valid_value("color", `color(${colorSpace} 1 1)`, `color(${resultColorSpace} 1 1 0)`); - test_valid_value("color", `color(${colorSpace} 1)`, `color(${resultColorSpace} 1 0 0)`); - test_valid_value("color", `color(${colorSpace})`, `color(${resultColorSpace} 0 0 0)`); - test_valid_value("color", `color(${colorSpace} 1 1 / .5)`, `color(${resultColorSpace} 1 1 0 / 0.5)`); - test_valid_value("color", `color(${colorSpace} 1 / 0.5)`, `color(${resultColorSpace} 1 0 0 / 0.5)`); - test_valid_value("color", `color(${colorSpace} / 50%)`, `color(${resultColorSpace} 0 0 0 / 0.5)`); test_valid_value("color", `color(${colorSpace} calc(0.5 + 1) calc(0.5 - 1) calc(0.5) / calc(-0.5 + 1))`, `color(${resultColorSpace} 1.5 -0.5 0.5 / 0.5)`); test_valid_value("color", `color(${colorSpace} none none none / none)`, `color(${resultColorSpace} none none none / none)`);