Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #9948 -- Corrected URLField validation to match RFC1035 (URL an…

…alog of #9890). Thanks to kratorius for the report and fix.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10574 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6590061a005b8772baee1a94d7799bcb58d9841d 1 parent 48b459a
Russell Keith-Magee authored April 16, 2009
2  django/forms/fields.py
@@ -533,7 +533,7 @@ def clean(self, data, initial=None):
533 533
 
534 534
 url_re = re.compile(
535 535
     r'^https?://' # http:// or https://
536  
-    r'(?:(?:[A-Z0-9-]+\.)+[A-Z]{2,6}|' #domain...
  536
+    r'(?:(?:[A-Z0-9]+(?:-*[A-Z0-9]+)*\.)+[A-Z]{2,6}|' #domain...
537 537
     r'localhost|' #localhost...
538 538
     r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
539 539
     r'(?::\d+)?' # optional port
22  tests/regressiontests/forms/fields.py
@@ -900,6 +900,10 @@
900 900
 u'http://www.example.com/'
901 901
 >>> f.clean('http://www.example.com:8000/test')
902 902
 u'http://www.example.com:8000/test'
  903
+>>> f.clean('valid-with-hyphens.com')
  904
+u'http://valid-with-hyphens.com/'
  905
+>>> f.clean('subdomain.domain.com')
  906
+u'http://subdomain.domain.com/'
903 907
 >>> f.clean('http://200.8.9.10')
904 908
 u'http://200.8.9.10/'
905 909
 >>> f.clean('http://200.8.9.10:8000/test')
@@ -924,6 +928,24 @@
924 928
 Traceback (most recent call last):
925 929
 ...
926 930
 ValidationError: [u'Enter a valid URL.']
  931
+>>> f.clean('http://invalid-.com')
  932
+Traceback (most recent call last):
  933
+...
  934
+ValidationError: [u'Enter a valid URL.']
  935
+>>> f.clean('http://-invalid.com')
  936
+Traceback (most recent call last):
  937
+...
  938
+ValidationError: [u'Enter a valid URL.']
  939
+>>> f.clean('http://inv-.alid-.com')
  940
+Traceback (most recent call last):
  941
+...
  942
+ValidationError: [u'Enter a valid URL.']
  943
+>>> f.clean('http://inv-.-alid.com')
  944
+Traceback (most recent call last):
  945
+...
  946
+ValidationError: [u'Enter a valid URL.']
  947
+>>> f.clean('http://valid-----hyphens.com')
  948
+u'http://valid-----hyphens.com/'
927 949
 
928 950
 >>> f = URLField(required=False)
929 951
 >>> f.clean('')

0 notes on commit 6590061

Please sign in to comment.
Something went wrong with that request. Please try again.