Skip to content

Commit c0a6375

Browse files
committed
Fix #189: fix the sanitizer to allow relative URLs again.
We regressed this when we added support for data URLs. Oops.
1 parent 9e91591 commit c0a6375

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

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.999999/1.0b7
5+
~~~~~~~~~~~~~~
6+
7+
Released on July 7, 2015
8+
9+
* Fix #189: fix the sanitizer to allow relative URLs again (as it did
10+
prior to 0.9999/1.0b5).
11+
12+
413
0.99999/1.0b6
514
~~~~~~~~~~~~~
615

html5lib/sanitizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def allowed_token(self, token, token_type):
208208
# remove replacement characters from unescaped characters
209209
val_unescaped = val_unescaped.replace("\ufffd", "")
210210
uri = urlparse.urlparse(val_unescaped)
211-
if uri:
211+
if uri and uri.scheme:
212212
if uri.scheme not in self.allowed_protocols:
213213
del attrs[attr]
214214
if uri.scheme == 'data':

html5lib/tests/test_sanitizer.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ def test_should_handle_astral_plane_characters():
4040
assert '<html:p xmlns:html="http://www.w3.org/1999/xhtml">\U0001d4b5 \U0001d538</html:p>' == sanitize_html("<p>&#x1d4b5; &#x1d538;</p>")
4141

4242

43+
def test_should_allow_relative_uris():
44+
assert '<html:p xmlns:html="http://www.w3.org/1999/xhtml"><html:a href="/example.com" /></html:p>' == sanitize_html('<p><a href="/example.com"></a></p>')
45+
46+
4347
def test_sanitizer():
4448
toxml = toxmlFactory()
4549
for tag_name in sanitizer.HTMLSanitizer.allowed_elements:

0 commit comments

Comments
 (0)