Fix color function preamble parsing
The current code accepts functions named after the color-space names
(like 'xyz').
Refactor the parsing of the preamble to first parse, check and consume
the function tokens and then parse a potential relative color and
resolve the color space.
Bug: 329820314
Change-Id: Ib9de0f64381d1a424ee31b19a10fc3488ba251a5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5375253
Reviewed-by: Rune Lillesveen <futhark@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/main@{#1274891}
diff --git a/css/css-color/parsing/color-invalid-color-function.html b/css/css-color/parsing/color-invalid-color-function.html
index 4decbb3..e02fb44 100644
--- a/css/css-color/parsing/color-invalid-color-function.html
+++ b/css/css-color/parsing/color-invalid-color-function.html
@@ -12,7 +12,10 @@
</head>
<body>
<script>
-for (const colorSpace of [ "srgb", "srgb-linear", "a98-rgb", "rec2020", "prophoto-rgb" ]) {
+const RGB_SPACES = ["srgb", "srgb-linear", "a98-rgb", "rec2020", "prophoto-rgb"];
+const XYZ_SPACES = ["xyz", "xyz-d50", "xyz-d65"];
+
+for (const colorSpace of RGB_SPACES) {
test_invalid_value("color", `color(${colorSpace} 0 0 0 0)`);
test_invalid_value("color", `color(${colorSpace} 0deg 0% 0)`);
test_invalid_value("color", `color(${colorSpace} 0% 0 0 1)`);
@@ -29,7 +32,7 @@
test_invalid_value("color", `color(${colorSpace} / 0.5)`);
}
-for (const colorSpace of [ "xyz", "xyz-d50", "xyz-d65" ]) {
+for (const colorSpace of XYZ_SPACES) {
test_invalid_value("color", `color(${colorSpace} 0 0 0 0)`);
test_invalid_value("color", `color(${colorSpace} 0deg 0% 0)`);
test_invalid_value("color", `color(${colorSpace} 0% 0 0 1)`);
@@ -59,6 +62,10 @@
test_invalid_value("color", "color(srgb 1 eggs 1)"); // Bad parameters
test_invalid_value("color", "color(srgb 1 1 1 / bacon)"); // Bad alpha
test_invalid_value("color", "color(srgb 1 1 1 / 1 cucumber)"); // Junk after alpha
+
+for (const colorSpace of [...RGB_SPACES, ...XYZ_SPACES]) {
+ test_invalid_value("color", `${colorSpace}(0 0 0)`);
+}
</script>
</body>
</html>