Fixed #32930 -- Fixed URLValidator when port numbers < 10.

This commit is contained in:
Wu Haotian 2021-07-16 16:30:24 +08:00 committed by Mariusz Felisiak
parent b96cc7f85e
commit 65b880b726
3 changed files with 7 additions and 2 deletions

View File

@ -87,7 +87,7 @@ class URLValidator(RegexValidator):
r'^(?:[a-z0-9.+-]*)://' # scheme is validated separately
r'(?:[^\s:@/]+(?::[^\s:@/]*)?@)?' # user:pass authentication
r'(?:' + ipv4_re + '|' + ipv6_re + '|' + host_re + ')'
r'(?::\d{2,5})?' # port
r'(?::\d{1,5})?' # port
r'(?:[/?#][^\s]*)?' # resource path
r'\Z', re.IGNORECASE)
message = _('Enter a valid URL.')
@ -129,7 +129,7 @@ class URLValidator(RegexValidator):
raise
else:
# Now verify IPv6 in the netloc part
host_match = re.search(r'^\[(.+)\](?::\d{2,5})?$', urlsplit(value).netloc)
host_match = re.search(r'^\[(.+)\](?::\d{1,5})?$', urlsplit(value).netloc)
if host_match:
potential_ip = host_match[1]
try:

View File

@ -60,6 +60,7 @@ http://1.2.03.4
http://1.2.3.04
http://.www.foo.bar/
http://.www.foo.bar./
http://[::1:2::3]:8/
http://[::1:2::3]:8080/
http://[]
http://[]:8080

View File

@ -2,6 +2,8 @@ http://www.djangoproject.com/
HTTP://WWW.DJANGOPROJECT.COM/
http://localhost/
http://example.com/
http://example.com:0
http://example.com:0/
http://example.com:65535
http://example.com:65535/
http://example.com./
@ -37,6 +39,8 @@ http://userid:@example.com:8080
http://userid:@example.com:8080/
http://userid:password@example.com
http://userid:password@example.com/
http://userid:password@example.com:8
http://userid:password@example.com:8/
http://userid:password@example.com:8080
http://userid:password@example.com:8080/
http://userid:password@example.com:65535