diff --git a/django/forms/fields.py b/django/forms/fields.py index 0ee66a9db3..acff7a54a9 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -704,9 +704,6 @@ class URLField(CharField): # 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 diff --git a/docs/releases/1.8.txt b/docs/releases/1.8.txt index ca67403f9e..326b58f412 100644 --- a/docs/releases/1.8.txt +++ b/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: diff --git a/tests/forms_tests/tests/test_fields.py b/tests/forms_tests/tests/test_fields.py index 454a8349d7..b06b34f26c 100644 --- a/tests/forms_tests/tests/test_fields.py +++ b/tests/forms_tests/tests/test_fields.py @@ -748,14 +748,14 @@ class FieldsTests(SimpleTestCase): self.assertWidgetRendersTo(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 @@ class FieldsTests(SimpleTestCase): 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 @@ class FieldsTests(SimpleTestCase): 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 @@ class FieldsTests(SimpleTestCase): def test_urlfield_5(self): f = URLField(min_length=15, max_length=20) self.assertWidgetRendersTo(f, '') - 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()