Skip to content

Commit

Permalink
Fixed #29528 -- Made URLValidator reject invalid characters in the us…
Browse files Browse the repository at this point in the history
…ername and password.
  • Loading branch information
timb07 authored and timgraham committed Jul 23, 2018
1 parent 5a017ee commit cdcf416
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion django/core/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class URLValidator(RegexValidator):

regex = _lazy_re_compile(
r'^(?:[a-z0-9\.\-\+]*)://' # scheme is validated separately
r'(?:\S+(?::\S*)?@)?' # user:pass authentication
r'(?:[^\s:@/]+(?::[^\s:@/]*)?@)?' # user:pass authentication
r'(?:' + ipv4_re + '|' + ipv6_re + '|' + host_re + ')'
r'(?::\d{2,5})?' # port
r'(?:[/?#][^\s]*)?' # resource path
Expand Down
6 changes: 6 additions & 0 deletions tests/validators/invalid_urls.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,9 @@ http://example.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.
http://example.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaa
https://test.[com
http://foo@bar@example.com
http://foo/bar@example.com
http://foo:bar:baz@example.com
http://foo:bar@baz@example.com
http://foo:bar/baz@example.com
http://invalid-.com/?m=foo@example.com
2 changes: 1 addition & 1 deletion tests/validators/valid_urls.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ http://foo.bar/?q=Test%20URL-encoded%20stuff
http://مثال.إختبار
http://例子.测试
http://उदाहरण.परीक्षा
http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com
http://-.~_!$&'()*+,;=%40:80%2f@example.com
http://xn--7sbb4ac0ad0be6cf.xn--p1ai
http://1337.net
http://a.b-c.de
Expand Down

0 comments on commit cdcf416

Please sign in to comment.