Loading django/forms/fields.py +13 −4 Original line number Diff line number Diff line Loading @@ -581,9 +581,18 @@ class URLField(CharField): def to_python(self, value): if value: if '://' not in value: url_fields = list(urlparse.urlsplit(value)) if not url_fields[0]: # If no URL scheme given, assume http:// value = u'http://%s' % value url_fields[0] = 'http' if not url_fields[1]: # Assume that if no domain is provided, that the path segment # contains the domain. url_fields[1] = url_fields[2] url_fields[2] = '' # Rebuild the url_fields list, since the domain segment may now # contain the path too. value = urlparse.urlunsplit(url_fields) url_fields = list(urlparse.urlsplit(value)) if not url_fields[2]: # the path portion may need to be added before query params Loading tests/regressiontests/forms/tests/fields.py +1 −0 Original line number Diff line number Diff line Loading @@ -495,6 +495,7 @@ class FieldsTests(TestCase): self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://inv-.-alid.com') self.assertEqual(u'http://valid-----hyphens.com/', f.clean('http://valid-----hyphens.com')) self.assertEqual(u'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(u'http://www.example.com/s/http://code.djangoproject.com/ticket/13804', f.clean('www.example.com/s/http://code.djangoproject.com/ticket/13804')) def test_url_regex_ticket11198(self): f = URLField() Loading Loading
django/forms/fields.py +13 −4 Original line number Diff line number Diff line Loading @@ -581,9 +581,18 @@ class URLField(CharField): def to_python(self, value): if value: if '://' not in value: url_fields = list(urlparse.urlsplit(value)) if not url_fields[0]: # If no URL scheme given, assume http:// value = u'http://%s' % value url_fields[0] = 'http' if not url_fields[1]: # Assume that if no domain is provided, that the path segment # contains the domain. url_fields[1] = url_fields[2] url_fields[2] = '' # Rebuild the url_fields list, since the domain segment may now # contain the path too. value = urlparse.urlunsplit(url_fields) url_fields = list(urlparse.urlsplit(value)) if not url_fields[2]: # the path portion may need to be added before query params Loading
tests/regressiontests/forms/tests/fields.py +1 −0 Original line number Diff line number Diff line Loading @@ -495,6 +495,7 @@ class FieldsTests(TestCase): self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://inv-.-alid.com') self.assertEqual(u'http://valid-----hyphens.com/', f.clean('http://valid-----hyphens.com')) self.assertEqual(u'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(u'http://www.example.com/s/http://code.djangoproject.com/ticket/13804', f.clean('www.example.com/s/http://code.djangoproject.com/ticket/13804')) def test_url_regex_ticket11198(self): f = URLField() Loading