#12988 closed (fixed)
Add support of IDN domains for URLField validator.
Reported by: | Nikolay | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Keywords: | IDN | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
With Django trunk (revision 12617), I have the following:
>>> from django.forms import URLField >>> URLField().clean('http://xn--e1afmkfd.xn--80akhbyknj4f/') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/niksite/webapps/django/datamining/dist/django/forms/fields.py", line 156, in clean self.run_validators(value) File "/home/niksite/webapps/django/datamining/dist/django/forms/fields.py", line 145, in run_validators raise ValidationError(errors) django.core.exceptions.ValidationError: [u'Enter a valid URL.'] >>> URLField().clean('http://пример.испытание/') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/niksite/webapps/django/datamining/dist/django/forms/fields.py", line 156, in clean self.run_validators(value) File "/home/niksite/webapps/django/datamining/dist/django/forms/fields.py", line 145, in run_validators raise ValidationError(errors) django.core.exceptions.ValidationError: [u'Enter a valid URL.']
BTW, these URLs are quit valid, moreover -- there is a wiki page after these URLs.
Attachments (1)
Change History (9)
comment:1 by , 15 years ago
comment:2 by , 15 years ago
milestone: | 1.2 |
---|
This is a feature request, and as such cannot happen for 1.2, which is feature-frozen.
comment:3 by , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:4 by , 15 years ago
We've been bitten by this in the Firefox Input application as well. If people want to report IDNs like http://www.правительство.рф/ == http://www.xn--80aealotwbjpid2k.xn--p1ai/ , the URLField will throw a ValidationError. Our downstream bug is: https://bugzilla.mozilla.org/show_bug.cgi?id=573105 .
We'd appreciate if this made it into a dot-release of Django 1.2!
by , 14 years ago
Attachment: | 12988.1.diff added |
---|
comment:5 by , 14 years ago
Has patch: | set |
---|---|
milestone: | → 1.3 |
I am the author of the patch on #9764.
It seems however that the problem you are describing has nothing to do with IDN handling pre-se but rather that the TLD in your example
(which is one of the IANA IDN test TLDs (click on IDNs)) has "too many" characters for the URLValidator regex which assumes that TLDs have 6 characters at most.
So the solution could be to either lift the restriction on TLD length or to add special handling for IDN TLDs (which are easily enough to distinguish, as they begin with "xn--" in IDNA encoded form) to the regex.