From 78332257aa5e5da8c599978c99545378487b2499 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 14 Nov 2023 16:32:13 +0100 Subject: [PATCH] :bug: Fix problem with color inputs --- common/src/app/common/colors.cljc | 5 +++-- common/test/common_tests/colors_test.cljc | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/colors.cljc b/common/src/app/common/colors.cljc index 101eecb98..7274b78a4 100644 --- a/common/src/app/common/colors.cljc +++ b/common/src/app/common/colors.cljc @@ -183,7 +183,7 @@ "yellowgreen" "#9acd32"}) (def ^:private hex-color-re - #"\#[0-9a-fA-F]{3,6}") + #"\#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})") (def ^:private rgb-color-re #"(?:|rgb)\((\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\)") @@ -431,7 +431,8 @@ (defn parse [color] (when (string? color) - (if (valid-hex-color? color) + (if (or (valid-hex-color? color) + (valid-hex-color? (dm/str "#" color))) (normalize-hex color) (or (some-> (parse-rgb color) (rgb->hex)) (get names (str/lower color)))))) diff --git a/common/test/common_tests/colors_test.cljc b/common/test/common_tests/colors_test.cljc index 277cf158c..a37e481fe 100644 --- a/common/test/common_tests/colors_test.cljc +++ b/common/test/common_tests/colors_test.cljc @@ -17,6 +17,7 @@ (t/is (false? (colors/valid-hex-color? "#"))) (t/is (false? (colors/valid-hex-color? "#qqqqqq"))) (t/is (true? (colors/valid-hex-color? "#aaa"))) + (t/is (false? (colors/valid-hex-color? "#aaaa"))) (t/is (true? (colors/valid-hex-color? "#fabada"))) )