From 277df1f03d2ce0ff30ecfee325a264dcde575598 Mon Sep 17 00:00:00 2001 From: akysil Date: Wed, 25 Nov 2026 07:05:25 -0600 Subject: [PATCH 1/2] fix: pass through CSS color() with a predefined color space instead of throwing --- packages/less/lib/less/functions/color.js | 8 +++++++- .../tests-error/eval/color-func-invalid-color-3.less | 3 +++ .../tests-error/eval/color-func-invalid-color-3.txt | 4 ++++ packages/test-data/tests-unit/functions/functions.css | 3 +++ packages/test-data/tests-unit/functions/functions.less | 3 +++ 5 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 packages/test-data/tests-error/eval/color-func-invalid-color-3.less create mode 100644 packages/test-data/tests-error/eval/color-func-invalid-color-3.txt diff --git a/packages/less/lib/less/functions/color.js b/packages/less/lib/less/functions/color.js index 6f5ee5b345..4787bd0a7e 100644 --- a/packages/less/lib/less/functions/color.js +++ b/packages/less/lib/less/functions/color.js @@ -4,6 +4,7 @@ import Quoted from '../tree/quoted.js'; import Anonymous from '../tree/anonymous.js'; import Expression from '../tree/expression.js'; import Operation from '../tree/operation.js'; +import Keyword from '../tree/keyword.js'; let colorFunctions; function clamp(val) { @@ -427,12 +428,17 @@ colorFunctions = { return new Anonymous(color.toARGB()); }, color: function(c) { + // CSS color(), e.g. color(display-p3 1 1 1), should be kept as is + if (arguments.length === 1 && c instanceof Expression && c.value[0] instanceof Keyword && + /^(from|srgb|srgb-linear|display-p3|display-p3-linear|a98-rgb|prophoto-rgb|rec2020|xyz|xyz-d50|xyz-d65|--.+)$/i.test(c.value[0].value)) { + return null; + } if ((c instanceof Quoted) && (/^#([A-Fa-f0-9]{8}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3,4})$/i.test(c.value))) { const val = c.value.slice(1); return new Color(val, undefined, `#${val}`); } - if ((c instanceof Color) || (c = Color.fromKeyword(c.value))) { + if ((c instanceof Color) || (typeof c.value === 'string' && (c = Color.fromKeyword(c.value)))) { c.value = undefined; return c; } diff --git a/packages/test-data/tests-error/eval/color-func-invalid-color-3.less b/packages/test-data/tests-error/eval/color-func-invalid-color-3.less new file mode 100644 index 0000000000..45e9ed9622 --- /dev/null +++ b/packages/test-data/tests-error/eval/color-func-invalid-color-3.less @@ -0,0 +1,3 @@ +.test-rule { + color: color(garbage 1 1 1); +} diff --git a/packages/test-data/tests-error/eval/color-func-invalid-color-3.txt b/packages/test-data/tests-error/eval/color-func-invalid-color-3.txt new file mode 100644 index 0000000000..9a080a0424 --- /dev/null +++ b/packages/test-data/tests-error/eval/color-func-invalid-color-3.txt @@ -0,0 +1,4 @@ +ArgumentError: Error evaluating function `color`: argument must be a color keyword or 3|4|6|8 digit hex e.g. #FFF in {path}color-func-invalid-color-3.less on line 2, column 10: +1 .test-rule { +2 color: color(garbage 1 1 1); +3 } diff --git a/packages/test-data/tests-unit/functions/functions.css b/packages/test-data/tests-unit/functions/functions.css index 723b97dc88..2f86216cba 100644 --- a/packages/test-data/tests-unit/functions/functions.css +++ b/packages/test-data/tests-unit/functions/functions.css @@ -125,6 +125,9 @@ color-quoted-keyword: #dda0dd; color-color: #dda0dd; color-keyword: #dda0dd; + color-css: color(display-p3 1 0.5 0); + color-css-p3-linear: color(display-p3-linear 1 0.5 0); + color-css-alpha: color(srgb 0.5 0 1 / 50%); tint: #898989; tint-full: #ffffff; tint-percent: #898989; diff --git a/packages/test-data/tests-unit/functions/functions.less b/packages/test-data/tests-unit/functions/functions.less index fa56935f29..4920f8a321 100644 --- a/packages/test-data/tests-unit/functions/functions.less +++ b/packages/test-data/tests-unit/functions/functions.less @@ -133,6 +133,9 @@ color-quoted-keyword: color("plum"); color-color: color(#dda0dd); color-keyword: color(plum); + color-css: color(display-p3 1 0.5 0); + color-css-p3-linear: color(display-p3-linear 1 0.5 0); + color-css-alpha: color(srgb 0.5 0 1 / 50%); tint: tint(#777777, 13); tint-full: tint(#777777, 100); tint-percent: tint(#777777, 13%); From bfea9885406cc66b4ded612819c90a313cfa0617 Mon Sep 17 00:00:00 2001 From: akysil Date: Wed, 25 Nov 2026 07:39:03 -0600 Subject: [PATCH 2/2] test: add color() fixtures for relative and custom color profiles --- packages/test-data/tests-unit/functions/functions.css | 2 ++ packages/test-data/tests-unit/functions/functions.less | 2 ++ 2 files changed, 4 insertions(+) diff --git a/packages/test-data/tests-unit/functions/functions.css b/packages/test-data/tests-unit/functions/functions.css index 2f86216cba..edaed7dda0 100644 --- a/packages/test-data/tests-unit/functions/functions.css +++ b/packages/test-data/tests-unit/functions/functions.css @@ -128,6 +128,8 @@ color-css: color(display-p3 1 0.5 0); color-css-p3-linear: color(display-p3-linear 1 0.5 0); color-css-alpha: color(srgb 0.5 0 1 / 50%); + color-css-relative: color(from red srgb r g b); + color-css-custom: color(--custom 1 0 0); tint: #898989; tint-full: #ffffff; tint-percent: #898989; diff --git a/packages/test-data/tests-unit/functions/functions.less b/packages/test-data/tests-unit/functions/functions.less index 4920f8a321..5d452b9029 100644 --- a/packages/test-data/tests-unit/functions/functions.less +++ b/packages/test-data/tests-unit/functions/functions.less @@ -136,6 +136,8 @@ color-css: color(display-p3 1 0.5 0); color-css-p3-linear: color(display-p3-linear 1 0.5 0); color-css-alpha: color(srgb 0.5 0 1 / 50%); + color-css-relative: color(from red srgb r g b); + color-css-custom: color(--custom 1 0 0); tint: tint(#777777, 13); tint-full: tint(#777777, 100); tint-percent: tint(#777777, 13%);