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
--- 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