Code

Opened 4 years ago

Closed 3 years ago

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

Download all attachments as: .zip

Change History (10)

Changed 4 years ago by Nedec

comment:1 Changed 4 years ago by Nedec

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from URLFile (in django.contrib.admin) rejects IDN domain to URLField (in django.contrib.admin) rejects IDN domain

comment:2 Changed 4 years ago by claudep

  • Component changed from django.contrib.admin to Forms
  • milestone set to 1.3
  • Triage Stage changed from Unreviewed to Accepted

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

comment:3 Changed 4 years ago by claudep

  • Component changed from Forms to Core 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 4 years ago by claudep

Encode url before passing it to urllib2.urlopen

Changed 4 years ago by claudep

With test

comment:4 Changed 4 years ago by claudep

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

comment:5 Changed 3 years ago by jezdez

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

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 3 years ago by jezdez

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

  • milestone 1.3 deleted

Milestone 1.3 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.