Ticket #13804: URLField.diff
File URLField.diff, 1.5 KB (added by , 14 years ago) |
---|
-
django/forms/fields.py
523 523 f.seek(0) 524 524 return f 525 525 526 url_scheme_re = re.compile(r'^[a-z][-+.a-z0-9]*://', re.IGNORECASE) 526 527 class URLField(CharField): 527 528 default_error_messages = { 528 529 'invalid': _(u'Enter a valid URL.'), … … 537 538 538 539 def to_python(self, value): 539 540 if value: 540 if '://' not in value:541 if not url_scheme_re.match(value): 541 542 # If no URL scheme given, assume http:// 542 543 value = u'http://%s' % value 543 544 url_fields = list(urlparse.urlsplit(value)) -
tests/regressiontests/forms/fields.py
491 491 self.assertRaisesErrorWithMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://inv-.-alid.com') 492 492 self.assertEqual(u'http://valid-----hyphens.com/', f.clean('http://valid-----hyphens.com')) 493 493 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/://')) 494 495 495 496 def test_url_regex_ticket11198(self): 496 497 f = URLField()