comparison 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
comparison
equal deleted inserted replaced
25460:bd4bcfa48c9e 25471:7298da81f5a9
324 324
325 key = args[1][0](context, mapping, args[1][1]) 325 key = args[1][0](context, mapping, args[1][1])
326 yield dictarg.get(key) 326 yield dictarg.get(key)
327 327
328 def _evalifliteral(arg, context, mapping): 328 def _evalifliteral(arg, context, mapping):
329 t = stringify(arg[0](context, mapping, arg[1])) 329 # get back to token tag to reinterpret string as template
330 if arg[0] == runstring or arg[0] == runrawstring: 330 strtoken = {runstring: 'string', runrawstring: 'rawstring'}.get(arg[0])
331 if strtoken:
331 yield runtemplate(context, mapping, 332 yield runtemplate(context, mapping,
332 compiletemplate(t, context, strtoken='rawstring')) 333 compiletemplate(arg[1], context, strtoken))
333 else: 334 else:
334 yield t 335 yield stringify(arg[0](context, mapping, arg[1]))
335 336
336 def if_(context, mapping, args): 337 def if_(context, mapping, args):
337 """:if(expr, then[, else]): Conditionally execute based on the result of 338 """:if(expr, then[, else]): Conditionally execute based on the result of
338 an expression.""" 339 an expression."""
339 if not (2 <= len(args) <= 3): 340 if not (2 <= len(args) <= 3):