@@ -39,8 +39,28 @@ def test_should_allow_relative_uris():
39
39
assert expected == sanitized
40
40
41
41
42
+ def test_invalid_data_uri ():
43
+ sanitized = sanitize_html ('<audio controls="" src="data:foobar"></audio>' )
44
+ expected = '<audio controls></audio>'
45
+ assert expected == sanitized
46
+
47
+
48
+ def test_invalid_ipv6_url ():
49
+ sanitized = sanitize_html ('<a href="h://]">' )
50
+ expected = "<a></a>"
51
+ assert expected == sanitized
52
+
53
+
54
+ def test_data_uri_disallowed_type ():
55
+ sanitized = sanitize_html ('<audio controls="" src="data:text/html,<html>"></audio>' )
56
+ expected = "<audio controls></audio>"
57
+ assert expected == sanitized
58
+
59
+
42
60
def test_sanitizer ():
43
61
for ns , tag_name in sanitizer .allowed_elements :
62
+ if ns != constants .namespaces ["html" ]:
63
+ continue
44
64
if tag_name in ['caption' , 'col' , 'colgroup' , 'optgroup' , 'option' , 'table' , 'tbody' , 'td' , 'tfoot' , 'th' , 'thead' , 'tr' ]:
45
65
continue # TODO
46
66
if tag_name != tag_name .lower ():
@@ -63,6 +83,8 @@ def test_sanitizer():
63
83
"<%s title='1'>foo <bad>bar</bad> baz</%s>" % (tag_name , tag_name ))
64
84
65
85
for ns , attribute_name in sanitizer .allowed_attributes :
86
+ if ns != None :
87
+ continue
66
88
if attribute_name != attribute_name .lower ():
67
89
continue # TODO
68
90
if attribute_name == 'style' :
@@ -82,18 +104,6 @@ def test_sanitizer():
82
104
"<img src=\" %s:%s\" >foo</a>" % (protocol , rest_of_uri ),
83
105
"""<img src="%s:%s">foo</a>""" % (protocol , rest_of_uri ))
84
106
85
- yield (runSanitizerTest , "test_invalid_data_uri" ,
86
- "<audio controls=\" \" ></audio>" ,
87
- "<audio controls=\" \" src=\" data:foobar\" ></audio>" )
88
-
89
- yield (runSanitizerTest , "test_invalid_ipv6_url" ,
90
- "<a>" ,
91
- "<a href=\" h://]\" >" )
92
-
93
- yield (runSanitizerTest , "test_data_uri_disallowed_type" ,
94
- "<audio controls=\" \" ></audio>" ,
95
- "<audio controls=\" \" src=\" data:text/html,<html>\" ></audio>" )
96
-
97
107
for protocol in sanitizer .allowed_protocols :
98
108
rest_of_uri = '//sub.domain.tld/path/object.ext'
99
109
if protocol == 'data' :
0 commit comments