templater: correctly deal with r"" strings
authorMatt Mackall <mpm@selenic.com>
Mon, 24 Sep 2012 15:24:27 -0500
changeset 17634 6b307730c9f0
parent 17633 312184f930b7
child 17635 8804e3cb51bd
templater: correctly deal with r"" strings
mercurial/templater.py
--- a/mercurial/templater.py	Sat Sep 22 13:04:36 2012 -0500
+++ b/mercurial/templater.py	Mon Sep 24 15:24:27 2012 -0500
@@ -36,18 +36,21 @@
             if c == 'r':
                 pos += 1
                 c = program[pos]
-                decode = lambda x: x
+                decode = False
             else:
-                decode = lambda x: x.decode('string-escape')
+                decode = True
             pos += 1
             s = pos
             while pos < end: # find closing quote
                 d = program[pos]
-                if d == '\\': # skip over escaped characters
+                if decode and d == '\\': # skip over escaped characters
                     pos += 2
                     continue
                 if d == c:
-                    yield ('string', decode(program[s:pos]), s)
+                    if not decode:
+                        yield ('string', program[s:pos].replace('\\', r'\\'), s)
+                        break
+                    yield ('string', program[s:pos].decode('string-escape'), s)
                     break
                 pos += 1
             else: