Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1113 from denibertovic/master

Fixed #18761 -- Added whitespace stripping to URLField and SlugField.
  • Loading branch information...
commit 7d050e8e9ce0e08aefe035a7e203c764fbfb544b 2 parents 710c59b + 186ec21
@aaugustin aaugustin authored
Showing with 16 additions and 0 deletions.
  1. +8 −0 django/forms/fields.py
  2. +8 −0 tests/forms_tests/tests/test_extra.py
View
8 django/forms/fields.py
@@ -670,6 +670,10 @@ def split_url(url):
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 @@ def to_python(self, value):
class SlugField(CharField):
default_validators = [validators.validate_slug]
+
+ def clean(self, value):
+ value = self.to_python(value).strip()
+ return super(SlugField, self).clean(value)
View
8 tests/forms_tests/tests/test_extra.py
@@ -569,6 +569,14 @@ def test_generic_ipaddress_normalization(self):
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:
Please sign in to comment.
Something went wrong with that request. Please try again.