From a9e188ccd6315d278795355a53bce6c1a63f5a50 Mon Sep 17 00:00:00 2001 From: Christopher Grebs Date: Fri, 22 Jan 2016 05:33:34 +0100 Subject: [PATCH] Fixed #26119 -- Fixed URLValidator crash on URLs with brackets. --- django/core/validators.py | 5 ++++- tests/validators/invalid_urls.txt | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/django/core/validators.py b/django/core/validators.py index 57e8d6e054..3c731f1459 100644 --- a/django/core/validators.py +++ b/django/core/validators.py @@ -124,7 +124,10 @@ class URLValidator(RegexValidator): except ValidationError as e: # Trivial case failed. Try for possible IDN domain if value: - scheme, netloc, path, query, fragment = urlsplit(value) + try: + scheme, netloc, path, query, fragment = urlsplit(value) + except ValueError: # for example, "Invalid IPv6 URL" + raise ValidationError(self.message, code=self.code) try: netloc = netloc.encode('idna').decode('ascii') # IDN -> ACE except UnicodeError: # invalid domain part diff --git a/tests/validators/invalid_urls.txt b/tests/validators/invalid_urls.txt index 701dc991ed..04a0b5fb1b 100644 --- a/tests/validators/invalid_urls.txt +++ b/tests/validators/invalid_urls.txt @@ -56,3 +56,4 @@ http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.example. http://example.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com http://example.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaa +https://test.[com