Opened 5 years ago

Closed 4 years ago

Last modified 4 years ago

#12988 closed (fixed)

Add support of IDN domains for URLField validator.

Reported by: niksite Owned by: nobody
Component: Forms Version: master
Severity: Keywords: IDN
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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 jezdez 5 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 Changed 5 years ago by UloPe

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 5 years ago by ubernostrum

  • milestone 1.2 deleted

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

comment:3 Changed 5 years ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 5 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 5 years ago by jezdez

comment:5 Changed 5 years ago by jezdez

  • Has patch set
  • milestone set to 1.3

comment:6 Changed 4 years ago by jezdez

  • Resolution set to fixed
  • Status changed from new to closed

In [15502]:

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

comment:7 Changed 4 years ago by jezdez

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 4 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

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