Mercurial > public > mercurial-scm > hg-stable
diff mercurial/templater.py @ 25471:7298da81f5a9 stable
templater: do not preprocess template string in "if" expression (issue4714)
The problem was spotted at 5ab28a2e9962, that says "this patch invokes it
with "strtoken='rawstring'" in "_evalifliteral()", because "t" is the result
of "arg" evaluation and it should be "string-escape"-ed if "arg" is "string"
expression." This workaround is no longer valid since 890845af1ac2 introduced
strict parsing of '\{'.
Instead, we should interpret bare token as "string" or "rawstring" template.
This is what buildmap() does at parsing phase.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 08 Jun 2015 18:14:22 +0900 |
parents | 890845af1ac2 |
children | ad14fb602e5e 9452112c8eb0 |
line wrap: on
line diff
--- a/mercurial/templater.py Fri Jun 05 12:57:21 2015 -0700 +++ b/mercurial/templater.py Mon Jun 08 18:14:22 2015 +0900 @@ -326,12 +326,13 @@ yield dictarg.get(key) def _evalifliteral(arg, context, mapping): - t = stringify(arg[0](context, mapping, arg[1])) - if arg[0] == runstring or arg[0] == runrawstring: + # get back to token tag to reinterpret string as template + strtoken = {runstring: 'string', runrawstring: 'rawstring'}.get(arg[0]) + if strtoken: yield runtemplate(context, mapping, - compiletemplate(t, context, strtoken='rawstring')) + compiletemplate(arg[1], context, strtoken)) else: - yield t + yield stringify(arg[0](context, mapping, arg[1])) def if_(context, mapping, args): """:if(expr, then[, else]): Conditionally execute based on the result of