Opened 6 years ago

Closed 6 years ago

Last modified 5 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: UI/UX:

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 6 years ago.
urlvalidator.diff (585 bytes) - added by Claude Paroz 6 years ago.
Encode url before passing it to urllib2.urlopen
urlvalidator2.diff (1.4 KB) - added by Claude Paroz 6 years ago.
With test

Download all attachments as: .zip

Change History (10)

Changed 6 years ago by Nedec

Attachment: url.png added

comment:1 Changed 6 years ago by Nedec

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Summary: URLFile (in django.contrib.admin) rejects IDN domainURLField (in django.contrib.admin) rejects IDN domain

comment:2 Changed 6 years ago by Claude Paroz

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 Changed 6 years ago by Claude Paroz

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

Changed 6 years ago by Claude Paroz

Attachment: urlvalidator.diff added

Encode url before passing it to urllib2.urlopen

Changed 6 years ago by Claude Paroz

Attachment: urlvalidator2.diff added

With test

comment:4 Changed 6 years ago by Claude Paroz

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

comment:5 Changed 6 years ago by Jannis Leidel

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

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

milestone: 1.3

Milestone 1.3 deleted

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