#36007: Dead code in URLValidator
-------------------------------------+-------------------------------------
Reporter: Mike Edmunds | Type:
| Cleanup/optimization
Status: new | Component:
| Uncategorized
Version: 5.1 | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
There's some dead code in django.core.validators.URLValidator which could
be removed:
* The entire
[https://github.com/django/django/blob/6f38697f90a14f1450a71c1e40aea0f5df7dca86/django/core/validators.py#L183-L193
"Trivial case failed. Try for possible IDN domain"] section is no longer
useful. This code attempts to re-validate a failed URL after encoding an
international domain name using IDNA 2003 ("punycode"). But the
URLValidator regular expressions have allowed ''all'' IDNs since
[https://github.com/django/django/commit/2e65d56156b622e2393dee1af66e9c799a51924f
Commit 2e65d56] (for #20003, in 2015), so the super call will never fail
with a validation error that switching to IDNA 2003 would let pass.
* The
[https://github.com/django/django/blob/6f38697f90a14f1450a71c1e40aea0f5df7dca86/django/core/validators.py#L131
`ul` unicode letters property] is no longer used. The regular expressions
that had used it were moved into DomainNameValidator in
[https://github.com/django/django/commit/4971a9afe5642569f3dcfcd3972ebb39e88dd457
Commit 4971a9a] (for #18119, in Django 5.1).
For the first case, one way to verify the code is no longer in use is to
run URLValidator on `https://މިހާރު.com`, which is a domain allowed by
IDNA 2008 but prohibited by IDNA 2003. If the punycode() branch were
coming into play, that URL would be rejected:
{{{#!python
from django.core.validators import URLValidator
URLValidator()("https://މިހާރު.com")
# (No error)
from django.utils.encoding import punycode
punycode("މިހާރު.com")
# UnicodeError: Violation of BIDI requirement 3
# encoding with 'idna' codec failed
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36007>
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 visit
https://groups.google.com/d/msgid/django-updates/01070193bd0a3b38-855d7bce-35ce-48cd-9c23-34bf699c53d6-000000%40eu-central-1.amazonses.com.