##// END OF EJS Templates
templater: do not preprocess template string in "if" expression (issue4714)...
Yuya Nishihara -
r25471:7298da81 stable
parent child Browse files
Show More
@@ -326,12 +326,13 b' def get(context, mapping, args):'
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
@@ -2284,6 +2284,17 b' Test leading backslashes:'
2284 \{rev} \{file} \\\head1
2284 \{rev} \{file} \\\head1
2285 $ cd ..
2285 $ cd ..
2286
2286
2287 Test leading backslashes in "if" expression (issue4714):
2288
2289 $ cd latesttag
2290 $ hg log -r 2 -T '{if("1", "\{rev}")} {if("1", r"\{rev}")}\n'
2291 {rev} \2
2292 $ hg log -r 2 -T '{if("1", "\\{rev}")} {if("1", r"\\{rev}")}\n'
2293 \2 \\2
2294 $ hg log -r 2 -T '{if("1", "\\\{rev}")} {if("1", r"\\\{rev}")}\n'
2295 \{rev} \\\2
2296 $ cd ..
2297
2287 "string-escape"-ed "\x5c\x786e" becomes r"\x6e" (once) or r"n" (twice)
2298 "string-escape"-ed "\x5c\x786e" becomes r"\x6e" (once) or r"n" (twice)
2288
2299
2289 $ hg log -R a -r 0 --template '{if("1", "\x5c\x786e", "NG")}\n'
2300 $ hg log -R a -r 0 --template '{if("1", "\x5c\x786e", "NG")}\n'
General Comments 0
You need to be logged in to leave comments. Login now