Skip to content

Commit c4a85fc

Browse files
authored
Merge pull request #377 from hugovk/upper-hex-in-css-colour
Allow uppercase hex chararcters in CSS colour check
2 parents d595d0a + a5a1900 commit c4a85fc

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,6 @@ target/
8080

8181
# Generated by parse.py -p
8282
stats.prof
83+
84+
# IDE
85+
.idea

html5lib/filters/sanitizer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ def sanitize_css(self, style):
855855
'padding']:
856856
for keyword in value.split():
857857
if keyword not in self.allowed_css_keywords and \
858-
not re.match(r"^(#[0-9a-f]+|rgb\(\d+%?,\d*%?,?\d*%?\)?|\d{0,2}\.?\d{0,2}(cm|em|ex|in|mm|pc|pt|px|%|,|\))?)$", keyword): # noqa
858+
not re.match(r"^(#[0-9a-fA-F]+|rgb\(\d+%?,\d*%?,?\d*%?\)?|\d{0,2}\.?\d{0,2}(cm|em|ex|in|mm|pc|pt|px|%|,|\))?)$", keyword): # noqa
859859
break
860860
else:
861861
clean.append(prop + ': ' + value + ';')

html5lib/tests/test_sanitizer.py

+12
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,15 @@ def test_sanitizer():
113113
yield (runSanitizerTest, "test_should_allow_uppercase_%s_uris" % protocol,
114114
"<img src=\"%s:%s\">foo</a>" % (protocol, rest_of_uri),
115115
"""<img src="%s:%s">foo</a>""" % (protocol, rest_of_uri))
116+
117+
118+
def test_lowercase_color_codes_in_style():
119+
sanitized = sanitize_html("<p style=\"border: 1px solid #a2a2a2;\"></p>")
120+
expected = '<p style=\"border: 1px solid #a2a2a2;\"></p>'
121+
assert expected == sanitized
122+
123+
124+
def test_uppercase_color_codes_in_style():
125+
sanitized = sanitize_html("<p style=\"border: 1px solid #A2A2A2;\"></p>")
126+
expected = '<p style=\"border: 1px solid #A2A2A2;\"></p>'
127+
assert expected == sanitized

0 commit comments

Comments
 (0)