templater: fix handling of \-escapes in raw string literals stable
authorYuya Nishihara <yuya@tcha.org>
Sun, 21 Jun 2015 13:24:43 +0900
branchstable
changeset 25638 6047b60cdd09
parent 25637 5eccebe23942
child 25662 ff5172c83002
child 25665 dc05a10e1e45
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
mercurial/templater.py
tests/test-command-template.t
--- 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