From 772ae7ed8a6f0fc8601fb4d6a7214634c36abdc5 Mon Sep 17 00:00:00 2001 From: ShawnNotFound Date: Mon, 2 Nov 2026 22:02:45 +0000 Subject: [PATCH 1/4] Accept CSS color syntax supported by plotly.js in ColorValidator Allow signed and exponent numbers, angle units other than deg, the none keyword, any color() color space and the transparent keyword. These are all accepted by plotly.js 4 but were rejected by the Python validator. --- _plotly_utils/basevalidators.py | 25 ++++++++++++------- .../validators/test_color_validator.py | 18 +++++++++++++ 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/_plotly_utils/basevalidators.py b/_plotly_utils/basevalidators.py index 1ffc63e5add..610d3166600 100644 --- a/_plotly_utils/basevalidators.py +++ b/_plotly_utils/basevalidators.py @@ -1138,13 +1138,24 @@ class ColorValidator(BaseValidator): }, """ - re_spaces_to_remove = re.compile(r"(? Date: Tue, 3 Nov 2026 00:07:39 +0000 Subject: [PATCH 2/4] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1632f922032..98832f2ea60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Fix `mpl_to_plotly` conversion of matplotlib contour lines and line collections: close contour rings ending with `Z` codes, support dash styles, convert date x-axes, separate disjoint subpaths with `None` separators, hide line collection traces from the legend by default, and group consecutive same-style lines into single traces [[#5770](https://github.com/plotly/plotly.py/pull/5770)], with thanks to @robertoffmoura for the contribution! - Fix `plotly.io.write_images` ignoring `layout.width`/`layout.height` (and the template's) and exporting every figure at the default 700x500 size; it now uses the same width/height priority as `write_image` and `to_image` [[#5784](https://github.com/plotly/plotly.py/pull/5784)], with thanks to @breken-ai for the contribution! - Fix color utilities mutating the list of colors passed to them [[#5836](https://github.com/plotly/plotly.py/pull/5836)], with thanks to @Enesuygurs for the contribution! +- Accept CSS color formats that plotly.js supports but the color validator rejected, such as negative `lab()`/`oklab()` components, `color()` values, angle units other than `deg`, the `none` keyword and `transparent` [[#5868](https://github.com/plotly/plotly.py/pull/5868)], with thanks to @ShawnNotFound for the contribution! ## [7.1.0] - 2026-09-15 From 0e4b97d37b8fe1703381b008d7033497cf48f629 Mon Sep 17 00:00:00 2001 From: ShawnNotFound Date: Sun, 8 Nov 2026 12:28:23 +0000 Subject: [PATCH 3/4] Avoid backtracking on long digit runs in the color regex \d+\.?\d* could split a run of digits in many ways, so an unclosed color function with many digits took quadratic time to reject. --- _plotly_utils/basevalidators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_plotly_utils/basevalidators.py b/_plotly_utils/basevalidators.py index 610d3166600..b76afde6a7c 100644 --- a/_plotly_utils/basevalidators.py +++ b/_plotly_utils/basevalidators.py @@ -1145,7 +1145,7 @@ class ColorValidator(BaseValidator): # A CSS color function argument: a number (which may be signed or use an # exponent) with an optional percent sign or angle unit, or `none`. _re_css_value = ( - r"(?:[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?(?:%|deg|grad|rad|turn)?|none)" + r"(?:[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?(?:%|deg|grad|rad|turn)?|none)" ) _re_css_sep = r"(?:\s*,\s*|\s+)" _re_css_alpha_sep = r"(?:\s*[,/]\s*|\s+)" From a6eb0a44b0a47c0d120e0dd91991690b0a2d4666 Mon Sep 17 00:00:00 2001 From: ShawnNotFound Date: Mon, 9 Nov 2026 20:50:13 +0000 Subject: [PATCH 4/4] Add changelog entry for rejecting colors with invalid spaces --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 063ab067602..0ad383604ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Fix `plotly.io.write_images` ignoring `layout.width`/`layout.height` (and the template's) and exporting every figure at the default 700x500 size; it now uses the same width/height priority as `write_image` and `to_image` [[#5784](https://github.com/plotly/plotly.py/pull/5784)], with thanks to @breken-ai for the contribution! - Fix color utilities mutating the list of colors passed to them [[#5836](https://github.com/plotly/plotly.py/pull/5836)], with thanks to @Enesuygurs for the contribution! - Accept CSS color formats that plotly.js supports but the color validator rejected, such as negative `lab()`/`oklab()` components, `color()` values, angle units other than `deg`, the `none` keyword and `transparent` [[#5868](https://github.com/plotly/plotly.py/pull/5868)], with thanks to @ShawnNotFound for the contribution! +- Reject color strings with spaces that CSS does not allow, such as `"light blue"`, `"# ff0000"` and `"hsl(0, 100 %, 50%)"`. The color validator used to remove these spaces and accept the strings, but plotly.js does not parse them [[#5868](https://github.com/plotly/plotly.py/pull/5868)], with thanks to @ShawnNotFound for the contribution! ## [7.1.0] - 2026-09-15