Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#14941 closed (fixed)

URLField (in django.contrib.admin) rejects IDN domain

Reported by: Nedec Owned by: nobody
Component: Core (Other) Version: 1.2
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I tried to add a new entry using the admin interface.
But when the URLField contains any unicode char (for IDN domains), like http://de.wikipedia.org/wiki/Tür, I am getting the following error:

Enter a valid URL.

According to the documentation, this bug was fixed in 1.2 and it does work in the shell:

>>> from django.core.validators import URLValidator
>>> v = URLValidator()
>>> v('http://de.wikipedia.org/wiki/Tür')
>>>

Attachments (3)

url.png (4.8 KB ) - added by Nedec 13 years ago.
urlvalidator.diff (585 bytes ) - added by Claude Paroz 13 years ago.
Encode url before passing it to urllib2.urlopen
urlvalidator2.diff (1.4 KB ) - added by Claude Paroz 13 years ago.
With test

Download all attachments as: .zip

Change History (10)

by Nedec, 13 years ago

Attachment: url.png added

comment:1 by Nedec, 13 years ago

Summary: URLFile (in django.contrib.admin) rejects IDN domainURLField (in django.contrib.admin) rejects IDN domain

comment:2 by Claude Paroz, 13 years ago

Component: django.contrib.adminForms
milestone: 1.3
Triage Stage: UnreviewedAccepted

I can reproduce this error even in a standard form. This is not related to the admin.

comment:3 by Claude Paroz, 13 years ago

Component: FormsCore framework
Has patch: set

After some research, this is related to the URL verification. Try:

>>> from django.core.validators import URLValidator
>>> v = URLValidator(verify_exists=True)
>>> v('http://de.wikipedia.org/wiki/Tür')
---------------------------------------------------------------------------
ValidationError                           Traceback (most recent call last)

/home/partage/Sauvegarde/Sites/bdn/Products/djangobdn/<ipython console> in <module>()

/usr/local/lib/python2.6/dist-packages/django/core/validators.pyc in __call__(self, value)
     85                 u = urllib2.urlopen(req)
     86             except ValueError:
---> 87                 raise ValidationError(_(u'Enter a valid URL.'), code='invalid')
     88             except: # urllib2.URLError, httplib.InvalidURL, etc.
     89                 raise ValidationError(_(u'This URL appears to be a broken link.'), code='invalid_link')

ValidationError: [u'Enter a valid URL.']

I'm attaching a patch that encodes url before passing it to urllib2. Testing is tricky, as it implies network access.

Note also that this is not solving IDN domain validation problem (#12988).

by Claude Paroz, 13 years ago

Attachment: urlvalidator.diff added

Encode url before passing it to urllib2.urlopen

by Claude Paroz, 13 years ago

Attachment: urlvalidator2.diff added

With test

comment:4 by Claude Paroz, 13 years ago

I saw there was already tests calling the network, so I added this one

comment:5 by Jannis Leidel, 13 years ago

Resolution: fixed
Status: newclosed

In [15504]:

Fixed #14941 -- Stop raising ValidationError in form fields that use the URLValidator and get a IDN domain passed. Thanks, Claude Paroz.

comment:6 by Jannis Leidel, 13 years ago

In [15511]:

[1.2.X] Fixed #14941 -- Stop raising ValidationError in form fields that use the URLValidator and get a IDN domain passed. Thanks, Claude Paroz.

Backport from trunk (r15504).

comment:7 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

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