##// END OF EJS Templates
templater: only recursively evaluate string literals as templates (issue4103)
Matt Mackall -
r20067:3d8bfe2e stable
parent child Browse files
Show More
@@ -386,9 +386,7 b' def templatelabel(context, mapping, args'
386 386 # i18n: "label" is a keyword
387 387 raise error.ParseError(_("label expects two arguments"))
388 388
389 thing = templater.stringify(args[1][0](context, mapping, args[1][1]))
390 thing = templater.runtemplate(context, mapping,
391 templater.compiletemplate(thing, context))
389 thing = templater._evalifliteral(args[1], context, mapping)
392 390
393 391 # apparently, repo could be a string that is the favicon?
394 392 repo = mapping.get('repo', '')
@@ -258,6 +258,13 b' def get(context, mapping, args):'
258 258 key = args[1][0](context, mapping, args[1][1])
259 259 yield dictarg.get(key)
260 260
261 def _evalifliteral(arg, context, mapping):
262 t = stringify(arg[0](context, mapping, arg[1]))
263 if arg[0] == runstring:
264 yield runtemplate(context, mapping, compiletemplate(t, context))
265 else:
266 yield t
267
261 268 def if_(context, mapping, args):
262 269 if not (2 <= len(args) <= 3):
263 270 # i18n: "if" is a keyword
@@ -265,11 +272,9 b' def if_(context, mapping, args):'
265 272
266 273 test = stringify(args[0][0](context, mapping, args[0][1]))
267 274 if test:
268 t = stringify(args[1][0](context, mapping, args[1][1]))
269 yield runtemplate(context, mapping, compiletemplate(t, context))
275 yield _evalifliteral(args[1], context, mapping)
270 276 elif len(args) == 3:
271 t = stringify(args[2][0](context, mapping, args[2][1]))
272 yield runtemplate(context, mapping, compiletemplate(t, context))
277 yield _evalifliteral(args[2], context, mapping)
273 278
274 279 def ifeq(context, mapping, args):
275 280 if not (3 <= len(args) <= 4):
@@ -279,11 +284,9 b' def ifeq(context, mapping, args):'
279 284 test = stringify(args[0][0](context, mapping, args[0][1]))
280 285 match = stringify(args[1][0](context, mapping, args[1][1]))
281 286 if test == match:
282 t = stringify(args[2][0](context, mapping, args[2][1]))
283 yield runtemplate(context, mapping, compiletemplate(t, context))
287 yield _evalifliteral(args[2], context, mapping)
284 288 elif len(args) == 4:
285 t = stringify(args[3][0](context, mapping, args[3][1]))
286 yield runtemplate(context, mapping, compiletemplate(t, context))
289 yield _evalifliteral(args[3], context, mapping)
287 290
288 291 def join(context, mapping, args):
289 292 if not (1 <= len(args) <= 2):
@@ -313,8 +316,7 b' def label(context, mapping, args):'
313 316 raise error.ParseError(_("label expects two arguments"))
314 317
315 318 # ignore args[0] (the label string) since this is supposed to be a a no-op
316 t = stringify(args[1][0](context, mapping, args[1][1]))
317 yield runtemplate(context, mapping, compiletemplate(t, context))
319 yield _evalifliteral(args[1], context, mapping)
318 320
319 321 def rstdoc(context, mapping, args):
320 322 if len(args) != 2:
@@ -1594,3 +1594,15 b' Test string escaping:'
1594 1594 <>\n<[>
1595 1595 <>\n<]>
1596 1596 <>\n<
1597
1598 Test recursive evaluation:
1599
1600 $ hg init r
1601 $ cd r
1602 $ echo a > a
1603 $ hg ci -Am '{rev}'
1604 adding a
1605 $ hg log -r 0 --template '{if(rev, desc)}\n'
1606 {rev}
1607 $ hg log -r 0 --template '{if(rev, "{author} {rev}")}\n'
1608 test 0
General Comments 0
You need to be logged in to leave comments. Login now