Skip to content

Commit 8bd7514

Browse files
timb07kvesteri
authored andcommitted
Fix for URLs with invalid characters in userinfo part (#70)
* Add another invalid test URL; #69 * Be stricter in characters allowed in userinfo URL part; #69 * Break long line for pep8 compliance; #69
1 parent 2d10184 commit 8bd7514

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

‎tests/test_url.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ def test_returns_true_on_valid_public_url(address, public):
116116
'http://.www.foo.bar/',
117117
'http://www.foo.bar./',
118118
'http://.www.foo.bar./',
119-
'http://127.12.0.260'
119+
'http://127.12.0.260',
120+
'http://example.com/">user@example.com',
120121
])
121122
def test_returns_failed_validation_on_invalid_url(address):
122123
assert isinstance(url(address), ValidationFailure)

‎validators/url.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
# protocol identifier
1111
u"(?:(?:https?|ftp)://)"
1212
# user:pass authentication
13-
u"(?:\S+(?::\S*)?@)?"
13+
u"(?:[-a-z\u00a1-\uffff0-9._~%!$&'()*+,;=:]+"
14+
u"(?::[-a-z0-9._~%!$&'()*+,;=:]*)?@)?"
1415
u"(?:"
1516
u"(?P<private_ip>"
1617
# IP address exclusion
@@ -43,9 +44,11 @@
4344
# port number
4445
u"(?::\d{2,5})?"
4546
# resource path
46-
u"(?:/\S*)?"
47+
u"(?:/[-a-z\u00a1-\uffff0-9._~%!$&'()*+,;=:@/]*)?"
4748
# query string
4849
u"(?:\?\S*)?"
50+
# fragment
51+
u"(?:#\S*)?"
4952
u"$",
5053
re.UNICODE | re.IGNORECASE
5154
)

0 commit comments

Comments
 (0)