Opened 14 years ago

Closed 13 years ago

Last modified 12 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 13 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 Changed 14 years ago by Ulrich Petri

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 Changed 14 years ago by James Bennett

milestone: 1.2

This is a feature request, and as such cannot happen for 1.2, which is feature-frozen.

comment:3 Changed 14 years ago by Russell Keith-Magee

Triage Stage: UnreviewedAccepted

comment:4 Changed 13 years ago by fwenzel

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!

Changed 13 years ago by Jannis Leidel

Attachment: 12988.1.diff added

comment:5 Changed 13 years ago by Jannis Leidel

Has patch: set
milestone: 1.3

comment:6 Changed 13 years ago by Jannis Leidel

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 Changed 13 years ago by Jannis Leidel

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 Changed 12 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

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