Ticket #11911: 11911.patch

File 11911.patch, 2.5 KB (added by Graham King, 13 years ago)

Split out just the part for this ticket. Added tests.

  • tests/regressiontests/defaultfilters/tests.py

     
    200200            u'<a href="http://31characteruri.com/test/"'\
    201201            u' rel="nofollow">...</a>')
    202202
     203        # Test url with brackets in it (#11911)
     204
     205        uri = 'http://en.wikipedia.org/wiki/Sibiu(Romania)'
     206        self.assertEqual(urlizetrunc(uri, 200),
     207            u'<a href="http://en.wikipedia.org/wiki/Sibiu%28Romania%29" '\
     208            u'rel="nofollow">http://en.wikipedia.org/wiki/Sibiu(Romania)</a>')
     209        self.assertEqual(urlizetrunc(uri, 40),
     210            u'<a href="http://en.wikipedia.org/wiki/Sibiu%28Romania%29" '\
     211            u'rel="nofollow">http://en.wikipedia.org/wiki/Sibiu(Ro...</a>')
     212
    203213    def test_urlize(self):
    204214        # Check normal urlize
    205215        self.assertEqual(urlize('http://google.com'),
  • django/utils/html.py

     
    117117    If autoescape is True, the link text and URLs will get autoescaped.
    118118    """
    119119    trim_url = lambda x, limit=trim_url_limit: limit is not None and (len(x) > limit and ('%s...' % x[:max(0, limit - 3)])) or x
     120    fix_trailing_bracket = lambda lead, middle, trail: (middle + ')', trail[1:]) if (trail.startswith(')') and not lead.endswith('(')) else (middle, trail)
    120121    safe_input = isinstance(text, SafeData)
    121122    words = word_split_re.split(force_unicode(text))
    122123    nofollow_attr = nofollow and ' rel="nofollow"' or ''
     
    129130            # Make URL we want to point to.
    130131            url = None
    131132            if middle.startswith('http://') or middle.startswith('https://'):
     133                middle, trail = fix_trailing_bracket(lead, middle, trail)
    132134                url = urlquote(middle, safe='/&=:;#?+*')
    133135            elif middle.startswith('www.') or ('@' not in middle and \
    134136                    middle and middle[0] in string.ascii_letters + string.digits and \
    135137                    (middle.endswith('.org') or middle.endswith('.net') or middle.endswith('.com'))):
     138                middle, trail = fix_trailing_bracket(lead, middle, trail)
    136139                url = urlquote('http://%s' % middle, safe='/&=:;#?+*')
    137140            elif '@' in middle and not ':' in middle and simple_email_re.match(middle):
    138141                url = 'mailto:%s' % middle
Back to Top