Ticket #16664: url_field.patch
File url_field.patch, 2.2 KB (added by , 13 years ago) |
---|
-
django/forms/fields.py
584 584 585 585 def to_python(self, value): 586 586 if value: 587 url_fields = list(urlparse.urlsplit(value)) 587 try: 588 value_splitted = urlparse.urlsplit(value) 589 except ValueError: 590 raise ValidationError(self.error_messages['invalid']) 591 592 url_fields = list(value_splitted) 588 593 if not url_fields[0]: 589 594 # If no URL scheme given, assume http:// 590 595 url_fields[0] = 'http' … … 596 601 # Rebuild the url_fields list, since the domain segment may now 597 602 # contain the path too. 598 603 value = urlparse.urlunsplit(url_fields) 599 url_fields = list(urlparse.urlsplit(value)) 604 try: 605 value_splitted = urlparse.urlsplit(value) 606 except ValueError: 607 raise ValidationError(self.error_messages['invalid']) 608 609 url_fields = list(value_splitted) 600 610 if not url_fields[2]: 601 611 # the path portion may need to be added before query params 602 612 url_fields[2] = '/' -
tests/regressiontests/forms/tests/fields.py
587 587 self.assertEqual(u'http://valid-----hyphens.com/', f.clean('http://valid-----hyphens.com')) 588 588 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')) 589 589 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')) 590 self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, '[a') 591 self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://[a') 590 592 591 593 def test_url_regex_ticket11198(self): 592 594 f = URLField()