summaryrefslogtreecommitdiff
path: root/django/core
diff options
context:
space:
mode:
authorMike Edmunds <medmunds@gmail.com>2024-12-12 17:26:48 -0800
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-12-13 16:10:34 +0100
commit54059125956789ad4c19b77eb7f5cde76eec0643 (patch)
tree7336d744274f670829eab1293de7be0abb439956 /django/core
parent9a891c387f752b1fa7c4d7b436cd8491e8f16eca (diff)
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).
Diffstat (limited to 'django/core')
-rw-r--r--django/core/validators.py40
1 files changed, 12 insertions, 28 deletions
diff --git a/django/core/validators.py b/django/core/validators.py
index 8732ddf7ad..c4e734c1d8 100644
--- a/django/core/validators.py
+++ b/django/core/validators.py
@@ -2,7 +2,7 @@ import ipaddress
import math
import re
from pathlib import Path
-from urllib.parse import urlsplit, urlunsplit
+from urllib.parse import urlsplit
from django.core.exceptions import ValidationError
from django.utils.deconstruct import deconstructible
@@ -128,8 +128,6 @@ validate_domain_name = DomainNameValidator()
@deconstructible
class URLValidator(RegexValidator):
- ul = "\u00a1-\uffff" # Unicode letters range (must not be a raw string).
-
# IP patterns
ipv4_re = (
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)
except ValueError:
raise ValidationError(self.message, code=self.code, params={"value": value})
- try:
- super().__call__(value)
- except ValidationError as e:
- # Trivial case failed. Try for possible IDN domain
- if value:
- scheme, netloc, path, query, fragment = splitted_url
- try:
- netloc = punycode(netloc) # IDN -> ACE
- except UnicodeError: # invalid domain part
- raise e
- 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}
- )
+ super().__call__(value)
+ # 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
# section 3.1. It's defined to be 255 bytes or less, but this includes