Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.0.X] Fixed #9948 -- Corrected URLField validation to match RFC1035…

… (URL analog of #9890). Thanks to kratorius for the report and fix.

Merge of r10574 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10577 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f80769d0892b6f4cf8ae47ad8d15c7f43605555e 1 parent 5f20587
@freakboy3742 freakboy3742 authored
Showing with 23 additions and 1 deletion.
  1. +1 −1  django/forms/fields.py
  2. +22 −0 tests/regressiontests/forms/fields.py
View
2  django/forms/fields.py
@@ -532,7 +532,7 @@ def clean(self, data, initial=None):
url_re = re.compile(
r'^https?://' # http:// or https://
- r'(?:(?:[A-Z0-9-]+\.)+[A-Z]{2,6}|' #domain...
+ r'(?:(?:[A-Z0-9]+(?:-*[A-Z0-9]+)*\.)+[A-Z]{2,6}|' #domain...
r'localhost|' #localhost...
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
r'(?::\d+)?' # optional port
View
22 tests/regressiontests/forms/fields.py
@@ -900,6 +900,10 @@
u'http://www.example.com/'
>>> f.clean('http://www.example.com:8000/test')
u'http://www.example.com:8000/test'
+>>> f.clean('valid-with-hyphens.com')
+u'http://valid-with-hyphens.com/'
+>>> f.clean('subdomain.domain.com')
+u'http://subdomain.domain.com/'
>>> f.clean('http://200.8.9.10')
u'http://200.8.9.10/'
>>> f.clean('http://200.8.9.10:8000/test')
@@ -924,6 +928,24 @@
Traceback (most recent call last):
...
ValidationError: [u'Enter a valid URL.']
+>>> f.clean('http://invalid-.com')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a valid URL.']
+>>> f.clean('http://-invalid.com')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a valid URL.']
+>>> f.clean('http://inv-.alid-.com')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a valid URL.']
+>>> f.clean('http://inv-.-alid.com')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a valid URL.']
+>>> f.clean('http://valid-----hyphens.com')
+u'http://valid-----hyphens.com/'
>>> f = URLField(required=False)
>>> f.clean('')
Please sign in to comment.
Something went wrong with that request. Please try again.