Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #22114 -- Stopped adding trailing slashes in URLField.to_python

Thanks coredumperror at gmail.com for the report and Tim Graham
for the review.
  • Loading branch information...
commit d320863878f097b5cbf33ace12e3adb5e02f27e0 1 parent b9e50e4
@claudep claudep authored
View
3  django/forms/fields.py
@@ -704,9 +704,6 @@ def split_url(url):
# Rebuild the url_fields list, since the domain segment may now
# contain the path too.
url_fields = split_url(urlunsplit(url_fields))
- if not url_fields[2]:
- # the path portion may need to be added before query params
- url_fields[2] = '/'
value = urlunsplit(url_fields)
return value
View
2  docs/releases/1.8.txt
@@ -173,7 +173,7 @@ Backwards incompatible changes in 1.8
Miscellaneous
~~~~~~~~~~~~~
-* ...
+* ``URLField.to_python`` no longer adds a trailing slash to pathless URLs.
.. _deprecated-features-1.8:
View
39 tests/forms_tests/tests/test_fields.py
@@ -748,14 +748,14 @@ def test_urlfield_1(self):
self.assertWidgetRendersTo(f, '<input type="url" name="f" id="id_f" />')
self.assertRaisesMessage(ValidationError, "'This field is required.'", f.clean, '')
self.assertRaisesMessage(ValidationError, "'This field is required.'", f.clean, None)
- self.assertEqual('http://localhost/', f.clean('http://localhost'))
- self.assertEqual('http://example.com/', f.clean('http://example.com'))
- self.assertEqual('http://example.com./', f.clean('http://example.com.'))
- self.assertEqual('http://www.example.com/', f.clean('http://www.example.com'))
+ self.assertEqual('http://localhost', f.clean('http://localhost'))
+ self.assertEqual('http://example.com', f.clean('http://example.com'))
+ self.assertEqual('http://example.com.', f.clean('http://example.com.'))
+ self.assertEqual('http://www.example.com', f.clean('http://www.example.com'))
self.assertEqual('http://www.example.com:8000/test', f.clean('http://www.example.com:8000/test'))
- self.assertEqual('http://valid-with-hyphens.com/', f.clean('valid-with-hyphens.com'))
- self.assertEqual('http://subdomain.domain.com/', f.clean('subdomain.domain.com'))
- self.assertEqual('http://200.8.9.10/', f.clean('http://200.8.9.10'))
+ self.assertEqual('http://valid-with-hyphens.com', f.clean('valid-with-hyphens.com'))
+ self.assertEqual('http://subdomain.domain.com', f.clean('subdomain.domain.com'))
+ self.assertEqual('http://200.8.9.10', f.clean('http://200.8.9.10'))
self.assertEqual('http://200.8.9.10:8000/test', f.clean('http://200.8.9.10:8000/test'))
self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'", f.clean, 'foo')
self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'", f.clean, 'http://')
@@ -768,7 +768,7 @@ def test_urlfield_1(self):
self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'", f.clean, 'http://-invalid.com')
self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'", f.clean, 'http://inv-.alid-.com')
self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'", f.clean, 'http://inv-.-alid.com')
- self.assertEqual('http://valid-----hyphens.com/', f.clean('http://valid-----hyphens.com'))
+ self.assertEqual('http://valid-----hyphens.com', f.clean('http://valid-----hyphens.com'))
self.assertEqual('http://some.idn.xyz\xe4\xf6\xfc\xdfabc.domain.com:123/blah', f.clean('http://some.idn.xyzäöüßabc.domain.com:123/blah'))
self.assertEqual('http://www.example.com/s/http://code.djangoproject.com/ticket/13804', f.clean('www.example.com/s/http://code.djangoproject.com/ticket/13804'))
self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'", f.clean, '[a')
@@ -787,8 +787,8 @@ def test_urlfield_2(self):
f = URLField(required=False)
self.assertEqual('', f.clean(''))
self.assertEqual('', f.clean(None))
- self.assertEqual('http://example.com/', f.clean('http://example.com'))
- self.assertEqual('http://www.example.com/', f.clean('http://www.example.com'))
+ self.assertEqual('http://example.com', f.clean('http://example.com'))
+ self.assertEqual('http://www.example.com', f.clean('http://www.example.com'))
self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'", f.clean, 'foo')
self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'", f.clean, 'http://')
self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'", f.clean, 'http://example')
@@ -798,25 +798,22 @@ def test_urlfield_2(self):
def test_urlfield_5(self):
f = URLField(min_length=15, max_length=20)
self.assertWidgetRendersTo(f, '<input id="id_f" type="url" name="f" maxlength="20" />')
- self.assertRaisesMessage(ValidationError, "'Ensure this value has at least 15 characters (it has 13).'", f.clean, 'http://f.com')
- self.assertEqual('http://example.com/', f.clean('http://example.com'))
- self.assertRaisesMessage(ValidationError, "'Ensure this value has at most 20 characters (it has 38).'", f.clean, 'http://abcdefghijklmnopqrstuvwxyz.com')
+ self.assertRaisesMessage(ValidationError, "'Ensure this value has at least 15 characters (it has 12).'", f.clean, 'http://f.com')
+ self.assertEqual('http://example.com', f.clean('http://example.com'))
+ self.assertRaisesMessage(ValidationError, "'Ensure this value has at most 20 characters (it has 37).'", f.clean, 'http://abcdefghijklmnopqrstuvwxyz.com')
def test_urlfield_6(self):
f = URLField(required=False)
- self.assertEqual('http://example.com/', f.clean('example.com'))
+ self.assertEqual('http://example.com', f.clean('example.com'))
self.assertEqual('', f.clean(''))
- self.assertEqual('https://example.com/', f.clean('https://example.com'))
+ self.assertEqual('https://example.com', f.clean('https://example.com'))
def test_urlfield_7(self):
f = URLField()
- self.assertEqual('http://example.com/', f.clean('http://example.com'))
+ self.assertEqual('http://example.com', f.clean('http://example.com'))
self.assertEqual('http://example.com/test', f.clean('http://example.com/test'))
-
- def test_urlfield_8(self):
- # ticket #11826
- f = URLField()
- self.assertEqual('http://example.com/?some_param=some_value', f.clean('http://example.com?some_param=some_value'))
+ self.assertEqual('http://example.com?some_param=some_value',
+ f.clean('http://example.com?some_param=some_value'))
def test_urlfield_9(self):
f = URLField()
Please sign in to comment.
Something went wrong with that request. Please try again.