Fixed #31548 -- Fixed URLValidator crash on non-strings.
This commit is contained in:
parent
bda6ade7b7
commit
ccb1cfb64e
|
@ -97,7 +97,9 @@ class URLValidator(RegexValidator):
|
||||||
self.schemes = schemes
|
self.schemes = schemes
|
||||||
|
|
||||||
def __call__(self, value):
|
def __call__(self, value):
|
||||||
# Check first if the scheme is valid
|
if not isinstance(value, str):
|
||||||
|
raise ValidationError(self.message, code=self.code)
|
||||||
|
# Check if the scheme is valid.
|
||||||
scheme = value.split('://')[0].lower()
|
scheme = value.split('://')[0].lower()
|
||||||
if scheme not in self.schemes:
|
if scheme not in self.schemes:
|
||||||
raise ValidationError(self.message, code=self.code)
|
raise ValidationError(self.message, code=self.code)
|
||||||
|
|
|
@ -222,6 +222,8 @@ TEST_DATA = [
|
||||||
(URLValidator(EXTENDED_SCHEMES), 'git+ssh://git@github.com/example/hg-git.git', None),
|
(URLValidator(EXTENDED_SCHEMES), 'git+ssh://git@github.com/example/hg-git.git', None),
|
||||||
|
|
||||||
(URLValidator(EXTENDED_SCHEMES), 'git://-invalid.com', ValidationError),
|
(URLValidator(EXTENDED_SCHEMES), 'git://-invalid.com', ValidationError),
|
||||||
|
(URLValidator(), None, ValidationError),
|
||||||
|
(URLValidator(), 56, ValidationError),
|
||||||
(URLValidator(), 'no_scheme', ValidationError),
|
(URLValidator(), 'no_scheme', ValidationError),
|
||||||
# Trailing newlines not accepted
|
# Trailing newlines not accepted
|
||||||
(URLValidator(), 'http://www.djangoproject.com/\n', ValidationError),
|
(URLValidator(), 'http://www.djangoproject.com/\n', ValidationError),
|
||||||
|
|
Loading…
Reference in New Issue