Commits

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.

  • Participants
  • Parent commits edfd89a
  • Branches stable

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)