Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #15229 -- Improved URLValidator to accept ftp:// links. Thanks,…

… codefisher and crayz_train

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15847 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f71384a52b606708b3bea5e9fbe75f1de8108701 1 parent ebd5682
Adrian Holovaty authored March 16, 2011
2  django/core/validators.py
@@ -45,7 +45,7 @@ def get_method(self):
45 45
 
46 46
 class URLValidator(RegexValidator):
47 47
     regex = re.compile(
48  
-        r'^https?://' # http:// or https://
  48
+        r'^(?:http|ftp)s?://' # http:// or https://
49 49
         r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' #domain...
50 50
         r'localhost|' #localhost...
51 51
         r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
12  tests/modeltests/validation/tests.py
@@ -61,6 +61,18 @@ def test_correct_url_value_passes(self):
61 61
         mtv = ModelToValidate(number=10, name='Some Name', url='http://www.djangoproject.com/')
62 62
         self.assertEqual(None, mtv.full_clean()) # This will fail if there's no Internet connection
63 63
 
  64
+    def test_correct_https_url_but_nonexisting(self):
  65
+        mtv = ModelToValidate(number=10, name='Some Name', url='https://www.djangoproject.com/')
  66
+        self.assertFieldFailsValidationWithMessage(mtv.full_clean, 'url', [u'This URL appears to be a broken link.'])
  67
+
  68
+    def test_correct_ftp_url_but_nonexisting(self):
  69
+        mtv = ModelToValidate(number=10, name='Some Name', url='ftp://ftp.google.com/we-love-microsoft.html')
  70
+        self.assertFieldFailsValidationWithMessage(mtv.full_clean, 'url', [u'This URL appears to be a broken link.'])
  71
+
  72
+    def test_correct_ftps_url_but_nonexisting(self):
  73
+        mtv = ModelToValidate(number=10, name='Some Name', url='ftps://ftp.google.com/we-love-microsoft.html')
  74
+        self.assertFieldFailsValidationWithMessage(mtv.full_clean, 'url', [u'This URL appears to be a broken link.'])
  75
+
64 76
     def test_text_greater_that_charfields_max_length_raises_erros(self):
65 77
         mtv = ModelToValidate(number=10, name='Some Name'*100)
66 78
         self.assertFailsValidation(mtv.full_clean, ['name',])

0 notes on commit f71384a

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