Ticket #13804: URLField.diff

File URLField.diff, 1.5 KB (added by Samus_, 14 years ago)
  • django/forms/fields.py

     
    523523            f.seek(0)
    524524        return f
    525525
     526url_scheme_re = re.compile(r'^[a-z][-+.a-z0-9]*://', re.IGNORECASE)
    526527class URLField(CharField):
    527528    default_error_messages = {
    528529        'invalid': _(u'Enter a valid URL.'),
     
    537538
    538539    def to_python(self, value):
    539540        if value:
    540             if '://' not in value:
     541            if not url_scheme_re.match(value):
    541542                # If no URL scheme given, assume http://
    542543                value = u'http://%s' % value
    543544            url_fields = list(urlparse.urlsplit(value))
  • tests/regressiontests/forms/fields.py

     
    491491        self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://inv-.-alid.com')
    492492        self.assertEqual(u'http://valid-----hyphens.com/', f.clean('http://valid-----hyphens.com'))
    493493        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'))
     494        self.assertEqual(u'http://www.example.com/://', f.clean('www.example.com/://'))
    494495
    495496    def test_url_regex_ticket11198(self):
    496497        f = URLField()
Back to Top