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)
|
||||
return value
|
||||
|
||||
def clean(self, value):
|
||||
value = self.to_python(value).strip()
|
||||
return super(URLField, self).clean(value)
|
||||
|
||||
|
||||
class BooleanField(Field):
|
||||
widget = CheckboxInput
|
||||
|
@ -1105,3 +1109,7 @@ class GenericIPAddressField(CharField):
|
|||
|
||||
class SlugField(CharField):
|
||||
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)
|
||||
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):
|
||||
class Test:
|
||||
if six.PY3:
|
||||
|
|
Loading…
Reference in New Issue