#32874: Allow URLValidator to accept schema relative URLs
-------------------------------------+-------------------------------------
Reporter: Maciej Strömich | Owner: Charlie
| Overton
Type: New feature | Status: assigned
Component: Core (Other) | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Maciej Strömich):
The issue with scheme relative urls lies in this code block
https://github.com/django/django/blob/stable/3.2.x/django/core/validators.py#L108-L110
in which scheme is split from url based on `://` which in the absolute url
makes total sense.
> The default list of accepted schemes is ['http', 'https', 'ftp',
'ftps'], so I wouldn't call this a bug. I guess the question is whether or
not there should be a way to allow schema relative URLs (assuming adding
// to schemes don't already work, I haven't tried it).
We were supporting schema relative urls with update to mentioned list in a
way like this {{{["", "http", "https"]}}} and it works in Django 2.2 well
if you're allowing to define the url in your forms like `://example.com`
instead of `//example.com`.
Between Django2.2 and Django 3.2
https://github.com/django/django/commit/b41d38ae26b1da9519a6cd765bc2f2ce7d355007
was introduced which changed the behaviour of `urlsplit()` call.
When upgrading to Django 3.2 URLValidator started to throw TypeError
exceptions because the default return value of
`urlsplit('://example.com).hostname` is `None` and it wasn't even getting
to the `ValidationError` line below.
In Django 2.2 the code was checking for `netloc` instead of `hostname`
which even if the netloc is not correctly found would return an empty
string `''` and the `len(urlsplit(..` code would pass because `''` is less
than 253 characters.
--
Ticket URL: <https://code.djangoproject.com/ticket/32874#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/072.d835dca88b84ebea239370c353fd4625%40djangoproject.com.