Merge pull request #1113 from denibertovic/master
Fixed #18761 -- Added whitespace stripping to URLField and SlugField.
This commit is contained in:
commit
7d050e8e9c
|
@ -670,6 +670,10 @@ class URLField(CharField):
|
||||||
value = urlunsplit(url_fields)
|
value = urlunsplit(url_fields)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
def clean(self, value):
|
||||||
|
value = self.to_python(value).strip()
|
||||||
|
return super(URLField, self).clean(value)
|
||||||
|
|
||||||
|
|
||||||
class BooleanField(Field):
|
class BooleanField(Field):
|
||||||
widget = CheckboxInput
|
widget = CheckboxInput
|
||||||
|
@ -1105,3 +1109,7 @@ class GenericIPAddressField(CharField):
|
||||||
|
|
||||||
class SlugField(CharField):
|
class SlugField(CharField):
|
||||||
default_validators = [validators.validate_slug]
|
default_validators = [validators.validate_slug]
|
||||||
|
|
||||||
|
def clean(self, value):
|
||||||
|
value = self.to_python(value).strip()
|
||||||
|
return super(SlugField, self).clean(value)
|
||||||
|
|
|
@ -569,6 +569,14 @@ class FormsExtraTestCase(TestCase, AssertFormErrorsMixin):
|
||||||
f = GenericIPAddressField(unpack_ipv4=True)
|
f = GenericIPAddressField(unpack_ipv4=True)
|
||||||
self.assertEqual(f.clean(' ::ffff:0a0a:0a0a'), '10.10.10.10')
|
self.assertEqual(f.clean(' ::ffff:0a0a:0a0a'), '10.10.10.10')
|
||||||
|
|
||||||
|
def test_slugfield_normalization(self):
|
||||||
|
f = SlugField()
|
||||||
|
self.assertEqual(f.clean(' aa-bb-cc '), 'aa-bb-cc')
|
||||||
|
|
||||||
|
def test_urlfield_normalization(self):
|
||||||
|
f = URLField()
|
||||||
|
self.assertEqual(f.clean('http://example.com/ '), 'http://example.com/')
|
||||||
|
|
||||||
def test_smart_text(self):
|
def test_smart_text(self):
|
||||||
class Test:
|
class Test:
|
||||||
if six.PY3:
|
if six.PY3:
|
||||||
|
|
Loading…
Reference in New Issue