#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)
Change History (10)
by , 15 years ago
comment:1 by , 15 years ago
| Summary: | URLFile (in django.contrib.admin) rejects IDN domain → URLField (in django.contrib.admin) rejects IDN domain |
|---|
comment:2 by , 15 years ago
| Component: | django.contrib.admin → Forms |
|---|---|
| milestone: | → 1.3 |
| Triage Stage: | Unreviewed → Accepted |
comment:3 by , 15 years ago
| Component: | Forms → 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).
by , 15 years ago
| Attachment: | urlvalidator.diff added |
|---|
Encode url before passing it to urllib2.urlopen
I can reproduce this error even in a standard form. This is not related to the admin.