mirror of
https://github.com/django/django.git
synced 2025-01-03 06:55:47 +00:00
Fixed #36007 -- Removed dead code from URLValidator.
The "Trivial case failed. Try for possible IDN domain" handling was obsoleted by ticket-20003, which adjusted the regular expressions to allow all international domain names (Refs #20003). Uses of `ul` were moved to DomainNameValidator in ticket-18119 (Refs #18119).
This commit is contained in:
parent
9a891c387f
commit
5405912595
@ -2,7 +2,7 @@ import ipaddress
|
|||||||
import math
|
import math
|
||||||
import re
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from urllib.parse import urlsplit, urlunsplit
|
from urllib.parse import urlsplit
|
||||||
|
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.utils.deconstruct import deconstructible
|
from django.utils.deconstruct import deconstructible
|
||||||
@ -128,8 +128,6 @@ validate_domain_name = DomainNameValidator()
|
|||||||
|
|
||||||
@deconstructible
|
@deconstructible
|
||||||
class URLValidator(RegexValidator):
|
class URLValidator(RegexValidator):
|
||||||
ul = "\u00a1-\uffff" # Unicode letters range (must not be a raw string).
|
|
||||||
|
|
||||||
# IP patterns
|
# IP patterns
|
||||||
ipv4_re = (
|
ipv4_re = (
|
||||||
r"(?:0|25[0-5]|2[0-4][0-9]|1[0-9]?[0-9]?|[1-9][0-9]?)"
|
r"(?:0|25[0-5]|2[0-4][0-9]|1[0-9]?[0-9]?|[1-9][0-9]?)"
|
||||||
@ -177,31 +175,17 @@ class URLValidator(RegexValidator):
|
|||||||
splitted_url = urlsplit(value)
|
splitted_url = urlsplit(value)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise ValidationError(self.message, code=self.code, params={"value": value})
|
raise ValidationError(self.message, code=self.code, params={"value": value})
|
||||||
try:
|
super().__call__(value)
|
||||||
super().__call__(value)
|
# Now verify IPv6 in the netloc part
|
||||||
except ValidationError as e:
|
host_match = re.search(r"^\[(.+)\](?::[0-9]{1,5})?$", splitted_url.netloc)
|
||||||
# Trivial case failed. Try for possible IDN domain
|
if host_match:
|
||||||
if value:
|
potential_ip = host_match[1]
|
||||||
scheme, netloc, path, query, fragment = splitted_url
|
try:
|
||||||
try:
|
validate_ipv6_address(potential_ip)
|
||||||
netloc = punycode(netloc) # IDN -> ACE
|
except ValidationError:
|
||||||
except UnicodeError: # invalid domain part
|
raise ValidationError(
|
||||||
raise e
|
self.message, code=self.code, params={"value": value}
|
||||||
url = urlunsplit((scheme, netloc, path, query, fragment))
|
)
|
||||||
super().__call__(url)
|
|
||||||
else:
|
|
||||||
raise
|
|
||||||
else:
|
|
||||||
# Now verify IPv6 in the netloc part
|
|
||||||
host_match = re.search(r"^\[(.+)\](?::[0-9]{1,5})?$", splitted_url.netloc)
|
|
||||||
if host_match:
|
|
||||||
potential_ip = host_match[1]
|
|
||||||
try:
|
|
||||||
validate_ipv6_address(potential_ip)
|
|
||||||
except ValidationError:
|
|
||||||
raise ValidationError(
|
|
||||||
self.message, code=self.code, params={"value": value}
|
|
||||||
)
|
|
||||||
|
|
||||||
# The maximum length of a full host name is 253 characters per RFC 1034
|
# The maximum length of a full host name is 253 characters per RFC 1034
|
||||||
# section 3.1. It's defined to be 255 bytes or less, but this includes
|
# section 3.1. It's defined to be 255 bytes or less, but this includes
|
||||||
|
Loading…
Reference in New Issue
Block a user