Yuya Nishihara avatar Yuya Nishihara committed a752837

infobar: use lambda to replace hash-like string by subrepo link (fixes #2484)

It's unsafe to use arbitrary subrepo name as a replacement pattern.

Comments (0)

Files changed (1)

tortoisehg/hgqt/qtlib.py

 
 def _linkifyHash(message, subrepo=''):
     if subrepo:
-        replaceexpr = r'<a href="repo:%s?\1">\1</a>' % subrepo
+        p = 'repo:%s?' % subrepo
     else:
-        replaceexpr = r'<a href="cset:\1">\1</a>'
+        p = 'cset:'
+    replaceexpr = lambda m: '<a href="%s">%s</a>' % (p + m.group(0), m.group(0))
     return _hashregex.sub(replaceexpr, message)
 
 def _linkifySubrepoRef(message, subrepo, hash=''):
     ...                subrepo='bar') #doctest: +NORMALIZE_WHITESPACE
     u'abort: <a href="repo:bar?0123456789ab">0123456789ab</a>!
     (in subrepo <a href="repo:bar?0123456789ab">bar</a>)<br>hint: foo<br>'
+
+    subrepo name containing regexp backreference, \g:
+
+    >>> linkifyMessage('abort: 0123456789ab! (in subrepo foo\\goo)\n',
+    ...                subrepo='foo\\goo') #doctest: +NORMALIZE_WHITESPACE
+    u'abort: <a href="repo:foo\\goo?0123456789ab">0123456789ab</a>!
+    (in subrepo <a href="repo:foo\\goo?0123456789ab">foo\\goo</a>)<br>'
     """
     message = unicode(message)
     message = _linkifyHash(message, subrepo)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.