Ticket #12989: 12989.diff
File 12989.diff, 2.8 KB (added by , 15 years ago) |
---|
-
django/core/validators.py
58 58 except ValidationError, e: 59 59 # Trivial case failed. Try for possible IDN domain 60 60 if value: 61 original = value62 61 value = smart_unicode(value) 63 s plitted= urlparse.urlsplit(value)62 scheme, netloc, path, query, fragment = urlparse.urlsplit(value) 64 63 try: 65 netloc _ace = splitted[1].encode('idna') # IDN -> ACE64 netloc = netloc.encode('idna') # IDN -> ACE 66 65 except UnicodeError: # invalid domain part 67 66 raise e 68 value = value.replace(splitted[1], netloc_ace) 69 # If no URL path given, assume / 70 if not splitted[2]: 71 value += u'/' 72 super(URLValidator, self).__call__(value) 73 # After validation revert ACE encoded domain-part to 74 # original (IDN) value as suggested by RFC 3490 75 value = original 67 url = urlparse.urlunsplit((scheme, netloc, path, query, fragment)) 68 super(URLValidator, self).__call__(url) 76 69 else: 77 70 raise 71 else: 72 url = value 78 73 79 74 if self.verify_exists: 80 75 import urllib2 … … 86 81 "User-Agent": self.user_agent, 87 82 } 88 83 try: 89 req = urllib2.Request( value, None, headers)84 req = urllib2.Request(url, None, headers) 90 85 u = urllib2.urlopen(req) 91 86 except ValueError: 92 87 raise ValidationError(_(u'Enter a valid URL.'), code='invalid') -
tests/regressiontests/forms/fields.py
531 531 f.clean('http://google.com/we-love-microsoft.html') # good domain, bad page 532 532 except ValidationError, e: 533 533 self.assertEqual("[u'This URL appears to be a broken link.']", str(e)) 534 # Valid and existent IDN 535 self.assertEqual(u'http://\u05e2\u05d1\u05e8\u05d9\u05ea.idn.icann.org/', f.clean(u'http://עברית.idn.icann.org/')) 536 # Valid but non-existent IDN 537 try: 538 f.clean(u'http://broken.עברית.idn.icann.org/') 539 except ValidationError, e: 540 self.assertEqual("[u'This URL appears to be a broken link.']", str(e)) 534 541 535 542 def test_urlfield_40(self): 536 543 f = URLField(verify_exists=True, required=False)