Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed errors introduced in 21f333b. Refs #17751

  • Loading branch information...
commit 5ae0c933a8572c173401386f9037901e6b5fff2b 1 parent cc53d9b
@apollo13 apollo13 authored
View
2  django/core/validators.py
@@ -129,7 +129,7 @@ def __call__(self, value):
slug_re = re.compile(r'^[-a-zA-Z0-9_]+$')
validate_slug = RegexValidator(slug_re, _("Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens."), 'invalid')
-ipv4_re = re.compile(r'^\s*(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\s*$')
+ipv4_re = re.compile(r'^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$')
validate_ipv4_address = RegexValidator(ipv4_re, _('Enter a valid IPv4 address.'), 'invalid')
View
16 django/forms/fields.py
@@ -1096,9 +1096,10 @@ class IPAddressField(CharField):
}
default_validators = [validators.validate_ipv4_address]
- def clean(self, value):
- value = self.to_python(value).strip()
- return super(IPAddressField, self).clean(value)
+ def to_python(self, value):
+ if value in EMPTY_VALUES:
+ return ''
+ return value.strip()
class GenericIPAddressField(CharField):
@@ -1111,16 +1112,13 @@ def __init__(self, protocol='both', unpack_ipv4=False, *args, **kwargs):
self.default_error_messages['invalid'] = invalid_error_message
super(GenericIPAddressField, self).__init__(*args, **kwargs)
- def clean(self, value):
- value = self.to_python(value).strip()
- return super(GenericIPAddressField, self).clean(value)
-
def to_python(self, value):
if value in validators.EMPTY_VALUES:
return ''
+ value = value.strip()
if value and ':' in value:
- return clean_ipv6_address(value,
- self.unpack_ipv4, self.error_messages['invalid'])
+ return clean_ipv6_address(value,
+ self.unpack_ipv4, self.error_messages['invalid'])
return value
View
18 tests/modeltests/validation/tests.py
@@ -116,54 +116,40 @@ class GenericIPAddressFieldTests(ValidationTestCase):
def test_correct_generic_ip_passes(self):
giptm = GenericIPAddressTestModel(generic_ip="1.2.3.4")
self.assertEqual(None, giptm.full_clean())
- giptm = GenericIPAddressTestModel(generic_ip=" 1.2.3.4 ")
- self.assertEqual(None, giptm.full_clean())
giptm = GenericIPAddressTestModel(generic_ip="2001::2")
self.assertEqual(None, giptm.full_clean())
- giptm = GenericIPAddressTestModel(generic_ip=" 2001::2 ")
- self.assertEqual(None, giptm.full_clean())
def test_invalid_generic_ip_raises_error(self):
giptm = GenericIPAddressTestModel(generic_ip="294.4.2.1")
self.assertFailsValidation(giptm.full_clean, ['generic_ip',])
- giptm = GenericIPAddressTestModel(generic_ip="1.2.3 .4")
- self.assertFailsValidation(giptm.full_clean, ['generic_ip',])
giptm = GenericIPAddressTestModel(generic_ip="1:2")
self.assertFailsValidation(giptm.full_clean, ['generic_ip',])
def test_correct_v4_ip_passes(self):
giptm = GenericIPAddressTestModel(v4_ip="1.2.3.4")
self.assertEqual(None, giptm.full_clean())
- giptm = GenericIPAddressTestModel(v4_ip=" 1.2.3.4 ")
- self.assertEqual(None, giptm.full_clean())
def test_invalid_v4_ip_raises_error(self):
giptm = GenericIPAddressTestModel(v4_ip="294.4.2.1")
self.assertFailsValidation(giptm.full_clean, ['v4_ip',])
- giptm = GenericIPAddressTestModel(v4_ip="294.4 .2.1")
- self.assertFailsValidation(giptm.full_clean, ['v4_ip',])
giptm = GenericIPAddressTestModel(v4_ip="2001::2")
self.assertFailsValidation(giptm.full_clean, ['v4_ip',])
def test_correct_v6_ip_passes(self):
giptm = GenericIPAddressTestModel(v6_ip="2001::2")
self.assertEqual(None, giptm.full_clean())
- giptm = GenericIPAddressTestModel(v6_ip=" 2001::2 ")
- self.assertEqual(None, giptm.full_clean())
def test_invalid_v6_ip_raises_error(self):
giptm = GenericIPAddressTestModel(v6_ip="1.2.3.4")
self.assertFailsValidation(giptm.full_clean, ['v6_ip',])
- giptm = GenericIPAddressTestModel(v6_ip="2001:: 2")
- self.assertFailsValidation(giptm.full_clean, ['v6_ip',])
giptm = GenericIPAddressTestModel(v6_ip="1:2")
self.assertFailsValidation(giptm.full_clean, ['v6_ip',])
def test_v6_uniqueness_detection(self):
# These two addresses are the same with different syntax
- giptm = GenericIPAddressTestModel(generic_ip=" 2001::1:0:0:0:0:2")
+ giptm = GenericIPAddressTestModel(generic_ip="2001::1:0:0:0:0:2")
giptm.save()
- giptm = GenericIPAddressTestModel(generic_ip="2001:0:1:2 ")
+ giptm = GenericIPAddressTestModel(generic_ip="2001:0:1:2")
self.assertFailsValidation(giptm.full_clean, ['generic_ip',])
def test_v4_unpack_uniqueness_detection(self):
Please sign in to comment.
Something went wrong with that request. Please try again.