diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -940,9 +940,7 @@ def show_changeset(ui, repo, opts, buffe tmpl = opts.get('template') style = None - if tmpl: - tmpl = templater.parsestring(tmpl, quoted=False) - else: + if not tmpl: style = opts.get('style') # ui settings diff --git a/mercurial/templater.py b/mercurial/templater.py --- a/mercurial/templater.py +++ b/mercurial/templater.py @@ -52,7 +52,7 @@ def tokenizer(data): if not decode: yield ('string', program[s:pos].replace('\\', r'\\'), s) break - yield ('string', program[s:pos].decode('string-escape'), s) + yield ('string', program[s:pos], s) break pos += 1 else: @@ -80,19 +80,19 @@ def compiletemplate(tmpl, context): parsed = [] pos, stop = 0, len(tmpl) p = parser.parser(tokenizer, elements) - while pos < stop: n = tmpl.find('{', pos) if n < 0: - parsed.append(("string", tmpl[pos:])) + parsed.append(("string", tmpl[pos:].decode("string-escape"))) break if n > 0 and tmpl[n - 1] == '\\': # escaped - parsed.append(("string", tmpl[pos:n - 1] + "{")) + parsed.append(("string", + (tmpl[pos:n - 1] + "{").decode("string-escape"))) pos = n + 1 continue if n > pos: - parsed.append(("string", tmpl[pos:n])) + parsed.append(("string", tmpl[pos:n].decode("string-escape"))) pd = [tmpl, n + 1, stop] parseres, pos = p.parse(pd) diff --git a/mercurial/templates/paper/shortlog.tmpl b/mercurial/templates/paper/shortlog.tmpl --- a/mercurial/templates/paper/shortlog.tmpl +++ b/mercurial/templates/paper/shortlog.tmpl @@ -80,8 +80,8 @@ return m ? m[1] : null; }, '.bigtable > tbody:nth-of-type(2)', - '\ - %text%\ + '\\ + %text%\\ ' ); diff --git a/tests/test-command-template.t b/tests/test-command-template.t --- a/tests/test-command-template.t +++ b/tests/test-command-template.t @@ -1586,3 +1586,11 @@ Test the strip function with chars speci h1c b a + +Test string escaping: + + $ hg log -R latesttag -r 0 --template '>\n<>\\n<{if(rev, "[>\n<>\\n<]")}>\n<>\\n<\n' + > + <>\n<[> + <>\n<]> + <>\n<