changeset 17634:6b307730c9f0

templater: correctly deal with r"" strings
author Matt Mackall <mpm@selenic.com>
date Mon, 24 Sep 2012 15:24:27 -0500
parents 312184f930b7
children 8804e3cb51bd
files mercurial/templater.py
diffstat 1 files changed, 7 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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: