Skip to content

Commit cccf13c

Browse files
author
Komal Dembla
committed
Allows uppercase color codes in style
1 parent 14d4851 commit cccf13c

File tree

5 files changed

+20
-2
lines changed

5 files changed

+20
-2
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ Patches and suggestions
4242
- Michael[tm] Smith
4343
- Marc Abramowitz
4444
- Jon Dufresne
45+
- Komal Dembla

CHANGES.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Change Log
22
----------
33

4+
0.999999999/1.0b11
5+
~~~~~~~~~~~~~~~~~~
6+
7+
Released on XXX
8+
9+
* Adds uppercase check (A-F) in the css regex to allow sanitizer to pass css
10+
of the format: border: 1px solid #A2A2A2.
11+
12+
413
0.999999999/1.0b10
514
~~~~~~~~~~~~~~~~~~
615

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2006-2013 James Graham and other contributors
1+
Copyright (c) 2006-2013 James Graham, Google Inc. and other contributors
22

33
Permission is hereby granted, free of charge, to any person obtaining
44
a copy of this software and associated documentation files (the

html5lib/filters/sanitizer.py

Lines changed: 1 addition & 1 deletion
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("^(#[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("^(#[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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,11 @@ 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_should_handle_uppercase_color_codes_in_style():
119+
sanitized = sanitize_html("<p style=\"border: 1px solid #A2A2A2;\"></p>")
120+
print sanitized
121+
expected = '<p style=\"border: 1px solid #A2A2A2;\"></p>'
122+
print expected
123+
assert expected == sanitized

0 commit comments

Comments
 (0)