Mercurial > public > mercurial-scm > hg
diff tests/test-command-template.t @ 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 | d4838302305c |
children | a54c0d830499 |
line wrap: on
line diff
--- a/tests/test-command-template.t Mon Mar 03 15:50:45 2014 +0900 +++ b/tests/test-command-template.t Mon Mar 10 01:01:42 2014 +0900 @@ -1622,6 +1622,39 @@ $ hg log -r 0 --template '{if(rev, "{author} {rev}")}\n' test 0 + $ hg branch -q 'text.{rev}' + $ echo aa >> aa + $ hg ci -u '{node|short}' -m 'desc to be wrapped desc to be wrapped' + + $ hg log -r 1 --template '{fill(desc, "20", author, branch)}' + {node|short}desc to + text.{rev}be wrapped + text.{rev}desc to be + text.{rev}wrapped (no-eol) + $ hg log -r 1 --template '{fill(desc, "20", "{node|short}:", "text.{rev}:")}' + bcc7ff960b8e:desc to + text.1:be wrapped + text.1:desc to be + text.1:wrapped (no-eol) + + $ hg log -r 1 --template '{sub(r"[0-9]", "-", author)}' + {node|short} (no-eol) + $ hg log -r 1 --template '{sub(r"[0-9]", "-", "{node|short}")}' + bcc-ff---b-e (no-eol) + + $ cat >> .hg/hgrc <<EOF + > [extensions] + > color= + > [color] + > mode=ansi + > text.{rev} = red + > text.1 = green + > EOF + $ hg log --color=always -r 1 --template '{label(branch, "text\n")}' + \x1b[0;31mtext\x1b[0m (esc) + $ hg log --color=always -r 1 --template '{label("text.{rev}", "text\n")}' + \x1b[0;32mtext\x1b[0m (esc) + Test branches inside if statement: $ hg log -r 0 --template '{if(branches, "yes", "no")}\n'