Ticket #11911: 11911-and-12183.patch

File 11911-and-12183.patch, 1.8 KB (added by Tom Mortimer-Jones, 14 years ago)

Joint patch for tickets #11911 and #12183

  • django/utils/html.py

     
    9292    If autoescape is True, the link text and URLs will get autoescaped.
    9393    """
    9494    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
     95    fix_trailing_bracket = lambda lead, middle, trail: (middle + ')', trail[1:]) if (trail.startswith(')') and not lead.endswith('(')) else (middle, trail)
    9596    safe_input = isinstance(text, SafeData)
    9697    words = word_split_re.split(force_unicode(text))
    97     nofollow_attr = nofollow and ' rel="nofollow"' or ''
    9898    for i, word in enumerate(words):
     99        nofollow_attr = nofollow and ' rel="nofollow"' or ''
    99100        match = None
    100101        if '.' in word or '@' in word or ':' in word:
    101102            match = punctuation_re.match(word)
     
    104105            # Make URL we want to point to.
    105106            url = None
    106107            if middle.startswith('http://') or middle.startswith('https://'):
     108                middle, trail = fix_trailing_bracket(lead, middle, trail)
    107109                url = urlquote(middle, safe='/&=:;#?+*')
    108110            elif middle.startswith('www.') or ('@' not in middle and \
    109111                    middle and middle[0] in string.ascii_letters + string.digits and \
    110112                    (middle.endswith('.org') or middle.endswith('.net') or middle.endswith('.com'))):
     113                middle, trail = fix_trailing_bracket(lead, middle, trail)
    111114                url = urlquote('http://%s' % middle, safe='/&=:;#?+*')
    112115            elif '@' in middle and not ':' in middle and simple_email_re.match(middle):
    113116                url = 'mailto:%s' % middle
Back to Top