Ticket #11826: rfc2616-ticket11826.patch
File rfc2616-ticket11826.patch, 1.8 KB (added by , 15 years ago) |
---|
-
django/forms/fields.py
537 537 r'localhost|' #localhost... 538 538 r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip 539 539 r'(?::\d+)?' # optional port 540 r'(?:/?| /\S+)$', re.IGNORECASE)540 r'(?:/?|[/?]\S+)$', re.IGNORECASE) 541 541 542 542 class URLField(RegexField): 543 543 default_error_messages = { … … 553 553 self.user_agent = validator_user_agent 554 554 555 555 def clean(self, value): 556 # If no URL scheme given, assume http:// 557 if value and '://' not in value: 558 value = u'http://%s' % value 559 # If no URL path given, assume / 560 if value and not urlparse.urlsplit(value)[2]: 561 value += '/' 556 if value: 557 if '://' not in value: 558 # If no URL scheme given, assume http:// 559 value = u'http://%s' % value 560 url_fields = list(urlparse.urlsplit(value)) 561 if not url_fields[2]: 562 # the path portion may need to be added before query params 563 url_fields[2] = '/' 564 value = urlparse.urlunsplit(url_fields) 562 565 value = super(URLField, self).clean(value) 563 566 if value == u'': 564 567 return value -
tests/regressiontests/forms/fields.py
972 972 Traceback (most recent call last): 973 973 ... 974 974 ValidationError: [u'Enter a valid URL.'] 975 >>> f.clean('http://example.com?some_param=some_value') # RFC 2616 3.2.3 976 u'http://example.com/?some_param=some_value' 975 977 >>> f.clean('http://.com') 976 978 Traceback (most recent call last): 977 979 ...