Mercurial > public > mercurial-scm > hg-stable
diff mercurial/templater.py @ 20661:7e627fe63e5e stable
templater: avoid recursive evaluation of string literals completely
Changeset 3d8bfe2ecf6d (released with 2.8.1) fixed "recursively
evaluate string literals as templates" problem (issue4103) by
introducing "_evalifliteral()".
But some parts in template expressions below are still processed by
the combination of "compiletemplate()" and "runtemplate()", and may
cause same problem unexpectedly.
- 'init' and 'hang' of 'fill(text, width, init, hang)'
- 'expr' of 'sub(pat, repl, expr)'
- 'label' of 'label(label, expr)'
This patch processes them by "_evalifliteral()" instead of the
combination of "compiletemplate()" and "runtemplate()" to avoid
recursive evaluation of string literals completely.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Mon, 10 Mar 2014 01:01:42 +0900 |
parents | 268a5ab5c27b |
children | a54c0d830499 |
line wrap: on
line diff
--- a/mercurial/templater.py Mon Mar 03 15:50:45 2014 +0900 +++ b/mercurial/templater.py Mon Mar 10 01:01:42 2014 +0900 @@ -234,12 +234,8 @@ except ValueError: raise error.ParseError(_("fill expects an integer width")) try: - initindent = stringify(args[2][0](context, mapping, args[2][1])) - initindent = stringify(runtemplate(context, mapping, - compiletemplate(initindent, context))) - hangindent = stringify(args[3][0](context, mapping, args[3][1])) - hangindent = stringify(runtemplate(context, mapping, - compiletemplate(hangindent, context))) + initindent = stringify(_evalifliteral(args[2], context, mapping)) + hangindent = stringify(_evalifliteral(args[3], context, mapping)) except IndexError: pass @@ -345,9 +341,7 @@ pat = stringify(args[0][0](context, mapping, args[0][1])) rpl = stringify(args[1][0](context, mapping, args[1][1])) - src = stringify(args[2][0](context, mapping, args[2][1])) - src = stringify(runtemplate(context, mapping, - compiletemplate(src, context))) + src = stringify(_evalifliteral(args[2], context, mapping)) yield re.sub(pat, rpl, src) methods = {