Mercurial > hg-stable
changeset 24948:db7463aa080f stable
templater: do not process \-escapes at parsestring() (issue4290)
This patch brings back pre-2.8.1 behavior.
The result of parsestring() is stored in templater's cache, t.cache, and then
it is parsed as a template string by compiletemplate(). So t.cache should keep
an unparsed string no matter if it is sourced from config value. Otherwise
backslashes would be processed twice.
The test vector is borrowed from 64b4f0cd7336.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 04 May 2015 09:54:01 +0900 |
parents | 5bc506ee87d2 |
children | 890845af1ac2 |
files | mercurial/templater.py tests/test-command-template.t |
diffstat | 2 files changed, 26 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/templater.py Tue May 05 11:15:17 2015 -0700 +++ b/mercurial/templater.py Mon May 04 09:54:01 2015 +0900 @@ -618,14 +618,13 @@ yield j def parsestring(s, quoted=True): - '''parse a string using simple c-like syntax. - string must be in quotes if quoted is True.''' + '''unwrap quotes if quoted is True''' if quoted: if len(s) < 2 or s[0] != s[-1]: raise SyntaxError(_('unmatched quotes')) - return s[1:-1].decode('string_escape') + return s[1:-1] - return s.decode('string_escape') + return s class engine(object): '''template expansion engine.
--- a/tests/test-command-template.t Tue May 05 11:15:17 2015 -0700 +++ b/tests/test-command-template.t Mon May 04 09:54:01 2015 +0900 @@ -2250,6 +2250,29 @@ <>\n<]> <>\n< + $ hg log -R latesttag -r 0 \ + > --config ui.logtemplate='>\n<>\\n<{if(rev, "[>\n<>\\n<]")}>\n<>\\n<\n' + > + <>\n<[> + <>\n<]> + <>\n< + + $ hg log -R latesttag -r 0 -T esc \ + > --config templates.esc='>\n<>\\n<{if(rev, "[>\n<>\\n<]")}>\n<>\\n<\n' + > + <>\n<[> + <>\n<]> + <>\n< + + $ cat <<'EOF' > esctmpl + > changeset = '>\n<>\\n<{if(rev, "[>\n<>\\n<]")}>\n<>\\n<\n' + > EOF + $ hg log -R latesttag -r 0 --style ./esctmpl + > + <>\n<[> + <>\n<]> + <>\n< + "string-escape"-ed "\x5c\x786e" becomes r"\x6e" (once) or r"n" (twice) $ hg log -R a -r 0 --template '{if("1", "\x5c\x786e", "NG")}\n'