Ticket #14941: urlvalidator2.diff

File urlvalidator2.diff, 1.4 KB (added by claudep, 5 years ago)

With test

  • django/core/validators.py

    commit 8f0f55ccba0ba4cea24df189b096194365da0e28
    Author: Claude Paroz <claude@2xlibre.net>
    Date:   Thu Dec 23 22:03:27 2010 +0100
    
        Encode url before passing it to urllib2
    
    diff --git a/django/core/validators.py b/django/core/validators.py
    index b1b82db..65a980b 100644
    a b class URLValidator(RegexValidator): 
    8181                "User-Agent": self.user_agent,
    8282            }
    8383            try:
    84                 req = urllib2.Request(url, None, headers)
     84                req = urllib2.Request(url.encode('utf-8'), None, headers)
    8585                u = urllib2.urlopen(req)
    8686            except ValueError:
    8787                raise ValidationError(_(u'Enter a valid URL.'), code='invalid')
  • tests/regressiontests/forms/tests/fields.py

    diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/fields.py
    index 93ca5c1..9302b85 100644
    a b class FieldsTests(TestCase): 
    539539            f.clean(u'http://broken.עברית.idn.icann.org/')
    540540        except ValidationError, e:
    541541            self.assertEqual("[u'This URL appears to be a broken link.']", str(e))
     542        # UTF-8 char in path
     543        self.assertEqual(u'http://de.wikipedia.org/wiki/T\xfcr', f.clean(u'http://de.wikipedia.org/wiki/T\xfcr'))
    542544
    543545    def test_urlfield_4(self):
    544546        f = URLField(verify_exists=True, required=False)
Back to Top