changeset 25638:6047b60cdd09 stable

templater: fix handling of \-escapes in raw string literals The backslash character should start escape sequences no matter if a string is prefixed with 'r'. They are just not interpreted as escape sequences in raw strings. revset.tokenize() handles them correctly, but templater didn't. https://docs.python.org/2/reference/lexical_analysis.html#string-literals
author Yuya Nishihara <yuya@tcha.org>
date Sun, 21 Jun 2015 13:24:43 +0900
parents 5eccebe23942
children ff5172c83002 dc05a10e1e45
files mercurial/templater.py tests/test-command-template.t
diffstat 2 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templater.py	Sat Jun 20 23:13:34 2015 +0900
+++ b/mercurial/templater.py	Sun Jun 21 13:24:43 2015 +0900
@@ -47,7 +47,7 @@
             s = pos
             while pos < end: # find closing quote
                 d = program[pos]
-                if decode and d == '\\': # skip over escaped characters
+                if d == '\\': # skip over escaped characters
                     pos += 2
                     continue
                 if d == c:
--- a/tests/test-command-template.t	Sat Jun 20 23:13:34 2015 +0900
+++ b/tests/test-command-template.t	Sun Jun 21 13:24:43 2015 +0900
@@ -2280,6 +2280,17 @@
   <>\n<]>
   <>\n<
 
+Test string escaping of quotes:
+
+  $ hg log -Ra -r0 -T '{"\""}\n'
+  "
+  $ hg log -Ra -r0 -T '{"\\\""}\n'
+  \"
+  $ hg log -Ra -r0 -T '{r"\""}\n'
+  \"
+  $ hg log -Ra -r0 -T '{r"\\\""}\n'
+  \\\"
+
 Test leading backslashes:
 
   $ cd latesttag