1
0
mirror of https://github.com/django/django.git synced 2025-10-26 07:06:08 +00:00

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: