Opened 15 years ago

Closed 14 years ago

Last modified 13 years ago

#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)

12988.1.diff (3.2 KB ) - added by Jannis Leidel 14 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 by Ulrich Petri, 15 years ago

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.

comment:2 by James Bennett, 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 Russell Keith-Magee, 15 years ago

Triage Stage: UnreviewedAccepted

comment:4 by fwenzel, 14 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 Jannis Leidel, 14 years ago

Attachment: 12988.1.diff added

comment:5 by Jannis Leidel, 14 years ago

Has patch: set
milestone: 1.3

comment:6 by Jannis Leidel, 14 years ago

Resolution: fixed
Status: newclosed

In [15502]:

Fixed #12988 -- Extended regular expression of the URLValidator to fully support IDN-URLs, especially the long TLDs.

comment:7 by Jannis Leidel, 14 years ago

In [15509]:

[1.2.X] Fixed #12988 -- Extended regular expression of the URLValidator to fully support IDN-URLs, especially the long TLDs.

Backport from trunk (r15502).

comment:8 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

Note: See TracTickets for help on using tickets.
Back to Top