Opened 4 years ago

Closed 3 years ago

Last modified 3 years ago

#13804 closed (fixed)

URLField validation fails with "://" on the path and no scheme

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


according to RFC3986[1] urls containing colons on the path are valid but the current validation fails when the scheme is missing and there's an empty path:

Python 2.6.4rc2 (r264rc2:75497, Oct 20 2009, 02:55:11)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.VERSION
(1, 3, 0, 'alpha', 0)
>>> from django.forms import URLField
>>> f = URLField()
>>> f.clean('')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/samus/django-trunk/django/forms/", line 164, in clean
  File "/home/samus/django-trunk/django/forms/", line 153, in run_validators
    raise ValidationError(errors)
django.core.exceptions.ValidationError: [u'Enter a valid URL.']



Attachments (1)

URLField.diff (1.5 KB) - added by Samus_ 4 years ago.

Download all attachments as: .zip

Change History (5)

Changed 4 years ago by Samus_

comment:1 Changed 4 years ago by adamnelson

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

I think urlsplit should be used instead of a custom regex. If scheme is None, then use 'http' as the default and rebuild the url out of the component parts. Don't use scheme='http' as that has a weird issue with urls like '/hello/world' not getting the default scheme.

comment:2 Changed 4 years ago by emulbreh

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 3 years ago by SmileyChris

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

(In [14657]) Fixes #13804 -- URLField validation failure for a url containing ':' on the path and no scheme

comment:4 Changed 3 years ago by SmileyChris

(In [14658]) Fixes #13804 -- URLField validation failure for a url containing ':' on the path and no scheme. Backport of r14657

Add Comment

Modify Ticket

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

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

Note: See TracTickets for help on using tickets.