Skip to content

Commit 29526c5

Browse files
committed
When URLs are invalid IPv6 URLs drop the attr rather than error
1 parent 01b1ebb commit 29526c5

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

html5lib/sanitizer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,11 @@ def allowed_token(self, token, token_type):
207207
unescape(attrs[attr])).lower()
208208
# remove replacement characters from unescaped characters
209209
val_unescaped = val_unescaped.replace("\ufffd", "")
210-
uri = urlparse.urlparse(val_unescaped)
210+
try:
211+
uri = urlparse.urlparse(val_unescaped)
212+
except ValueError:
213+
uri = None
214+
del attrs[attr]
211215
if uri and uri.scheme:
212216
if uri.scheme not in self.allowed_protocols:
213217
del attrs[attr]

html5lib/tests/test_sanitizer.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ def test_sanitizer():
113113
"<audio controls=\"\" src=\"data:foobar\"></audio>",
114114
toxml)
115115

116+
yield (runSanitizerTest, "test_invalid_ipv6_url",
117+
"<a>",
118+
"<a href=\"h://]\">",
119+
toxml)
120+
116121
yield (runSanitizerTest, "test_data_uri_disallowed_type",
117122
"<audio controls=\"\"></audio>",
118123
"<audio controls=\"\" src=\"data:text/html,<html>\"></audio>",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy