Skip to content

Commit 011c3be

Browse files
committedSep 3, 2022
utils: color validation, allow rgba colors
1 parent cc99690 commit 011c3be

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed
 

‎src/badges/_html_colors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from re import compile
55

66

7-
RE_HEX_COLOR = compile(r"^#([0-9a-fA-F]{3}){1,2}$")
7+
RE_HEX_COLOR = compile(r"#([0-9a-fA-F]{3}){1,2}|#[0-9a-fA-F]{8}")
88

99
# this code is directly taken from the `colour` package
1010
# see https://github.com/vaab/colour/blob/11f138eb7841d2045160b378a2eec0c2321144c0/colour.py#L52-L199

‎tests/utils/test_check_html_color.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@
66
@pytest.mark.parametrize(
77
("color", "expected"),
88
[
9-
("#", False),
10-
("red", True),
11-
("Red", False),
129
("#f00", True),
13-
("#f0", False),
1410
("#ff0000", True),
11+
("#ff0000ff", True),
12+
("#", False),
13+
("#f0", False),
14+
("#f00f", False),
15+
("#f00f0", False),
1516
("#ff0000f", False),
17+
("#ff0000ff0", False),
18+
("#ff0000ff00", False),
19+
("red", True),
20+
("Red", False),
21+
("re", False),
22+
("rede", False),
1623
("green slime", False),
1724
],
1825
)

0 commit comments

Comments
 (0)
Please sign in to comment.