diff --git a/django/newforms/fields.py b/django/newforms/fields.py index 0b883bfad1..308790b07a 100644 --- a/django/newforms/fields.py +++ b/django/newforms/fields.py @@ -288,6 +288,8 @@ class URLField(RegexField): def clean(self, value): value = RegexField.clean(self, value) + if not self.required and value == u'': + return value if self.verify_exists: import urllib2 from django.conf import settings diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py index bfe36a467e..2ae10dc0d6 100644 --- a/tests/regressiontests/forms/tests.py +++ b/tests/regressiontests/forms/tests.py @@ -1331,6 +1331,11 @@ ValidationError: [u'This URL appears to be a broken link.'] Traceback (most recent call last): ... ValidationError: [u'This URL appears to be a broken link.'] +>>> f = URLField(verify_exists=True, required=False) +>>> f.clean('') +u'' +>>> f.clean('http://www.google.com') # This will fail if there's no Internet connection +u'http://www.google.com' EmailField also access min_length and max_length parameters, for convenience. >>> f = URLField(min_length=15, max_length=20)