changeset 4303:4b7a790d9702

urlify: use look behind and ahead in hash regexp This makes it match hashes only separated by a single whitespace - such as space or newline.
author Mads Kiilerich <madski@unity3d.com>
date Fri, 18 Jul 2014 18:44:54 +0200
parents 916be70ff883
children 0f4402c519ff
files kallithea/lib/helpers.py
diffstat 1 files changed, 3 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/helpers.py	Tue Dec 10 19:30:37 2013 +0100
+++ b/kallithea/lib/helpers.py	Fri Jul 18 18:44:54 2014 +0200
@@ -1244,28 +1244,15 @@
     :param repository: repo name to build the URL with
     """
     from pylons import url  # doh, we need to re-import url to mock it later
-    URL_PAT = re.compile(r'(^|\s)([0-9a-fA-F]{12,40})($|\s)')
 
     def url_func(match_obj):
-        rev = match_obj.groups()[1]
-        pref = match_obj.groups()[0]
-        suf = match_obj.groups()[2]
-
-        tmpl = (
-        '%(pref)s<a class="%(cls)s" href="%(url)s">'
-        '%(rev)s</a>%(suf)s'
-        )
-        return tmpl % {
-         'pref': pref,
-         'cls': 'revision-link',
+        rev = match_obj.group(0)
+        return '<a class="revision-link" href="%(url)s">%(rev)s</a>' % {
          'url': url('changeset_home', repo_name=repository, revision=rev),
          'rev': rev,
-         'suf': suf
         }
 
-    newtext = URL_PAT.sub(url_func, text_)
-
-    return newtext
+    return re.sub(r'(?:^|(?<=\s))([0-9a-fA-F]{12,40})(?=$|\s|[.,:])', url_func, text_)
 
 
 def urlify_commit(text_, repository, link_=None):