Ticket #19070: 19070-2.diff

File 19070-2.diff, 1.9 KB (added by tom@…, 3 years ago)
  • django/utils/html.py

    diff --git a/django/utils/html.py b/django/utils/html.py
    index d914234..25605be 100644
    a b fix_ampersands = allow_lazy(fix_ampersands, six.text_type) 
    150150def smart_urlquote(url):
    151151    "Quotes a URL if it isn't already quoted."
    152152    # Handle IDN before quoting.
    153     scheme, netloc, path, query, fragment = urlsplit(url)
    154153    try:
    155         netloc = netloc.encode('idna').decode('ascii') # IDN -> ACE
    156     except UnicodeError: # invalid domain part
     154        scheme, netloc, path, query, fragment = urlsplit(url)
     155        try:
     156            netloc = netloc.encode('idna').decode('ascii') # IDN -> ACE
     157        except UnicodeError: # invalid domain part
     158            pass
     159        else:
     160            url = urlunsplit((scheme, netloc, path, query, fragment))
     161    except ValueError:
     162        # invalid IPv6 URL (normally square brackets in hostname part).
    157163        pass
    158     else:
    159         url = urlunsplit((scheme, netloc, path, query, fragment))
    160164
    161165    # An URL is considered unquoted if it contains no % characters or
    162166    # contains a % not followed by two hexadecimal digits. See #9655.
  • tests/regressiontests/defaultfilters/tests.py

    diff --git a/tests/regressiontests/defaultfilters/tests.py b/tests/regressiontests/defaultfilters/tests.py
    index 52268da..8596f8c 100644
    a b class DefaultFiltersTests(TestCase): 
    310310        self.assertEqual(urlize('[see www.example.com]'),
    311311            '[see <a href="http://www.example.com" rel="nofollow">www.example.com</a>]' )
    312312
     313        # Check urlize doesn't crash when square bracket is prepended to url (#19070)
     314        self.assertEqual(urlize('see test[at[example.com'),
     315            'see <a href="http://test[at[example.com" rel="nofollow">test[at[example.com</a>' )
     316
    313317
    314318    def test_wordcount(self):
    315319        self.assertEqual(wordcount(''), 0)
Back to Top