diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
index 99c4b8f79324ad2ca00bf08228c87a2b40cec2af_bWVyY3VyaWFsL2NtZHV0aWwucHk=..64b4f0cd73369185656a36ab8823f1ac082d1d23_bWVyY3VyaWFsL2NtZHV0aWwucHk= 100644
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -940,9 +940,7 @@
 
     tmpl = opts.get('template')
     style = None
-    if tmpl:
-        tmpl = templater.parsestring(tmpl, quoted=False)
-    else:
+    if not tmpl:
         style = opts.get('style')
 
     # ui settings
diff --git a/mercurial/templater.py b/mercurial/templater.py
index 99c4b8f79324ad2ca00bf08228c87a2b40cec2af_bWVyY3VyaWFsL3RlbXBsYXRlci5weQ==..64b4f0cd73369185656a36ab8823f1ac082d1d23_bWVyY3VyaWFsL3RlbXBsYXRlci5weQ== 100644
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -52,7 +52,7 @@
                     if not decode:
                         yield ('string', program[s:pos].replace('\\', r'\\'), s)
                         break
-                    yield ('string', program[s:pos].decode('string-escape'), s)
+                    yield ('string', program[s:pos], s)
                     break
                 pos += 1
             else:
@@ -80,7 +80,6 @@
     parsed = []
     pos, stop = 0, len(tmpl)
     p = parser.parser(tokenizer, elements)
-
     while pos < stop:
         n = tmpl.find('{', pos)
         if n < 0:
@@ -84,7 +83,7 @@
     while pos < stop:
         n = tmpl.find('{', pos)
         if n < 0:
-            parsed.append(("string", tmpl[pos:]))
+            parsed.append(("string", tmpl[pos:].decode("string-escape")))
             break
         if n > 0 and tmpl[n - 1] == '\\':
             # escaped
@@ -88,7 +87,8 @@
             break
         if n > 0 and tmpl[n - 1] == '\\':
             # escaped
-            parsed.append(("string", tmpl[pos:n - 1] + "{"))
+            parsed.append(("string",
+                           (tmpl[pos:n - 1] + "{").decode("string-escape")))
             pos = n + 1
             continue
         if n > pos:
@@ -92,7 +92,7 @@
             pos = n + 1
             continue
         if n > pos:
-            parsed.append(("string", tmpl[pos:n]))
+            parsed.append(("string", tmpl[pos:n].decode("string-escape")))
 
         pd = [tmpl, n + 1, stop]
         parseres, pos = p.parse(pd)
diff --git a/mercurial/templates/paper/shortlog.tmpl b/mercurial/templates/paper/shortlog.tmpl
index 99c4b8f79324ad2ca00bf08228c87a2b40cec2af_bWVyY3VyaWFsL3RlbXBsYXRlcy9wYXBlci9zaG9ydGxvZy50bXBs..64b4f0cd73369185656a36ab8823f1ac082d1d23_bWVyY3VyaWFsL3RlbXBsYXRlcy9wYXBlci9zaG9ydGxvZy50bXBs 100644
--- a/mercurial/templates/paper/shortlog.tmpl
+++ b/mercurial/templates/paper/shortlog.tmpl
@@ -80,8 +80,8 @@
                 return m ? m[1] : null;
             },
             '.bigtable > tbody:nth-of-type(2)',
-            '<tr class="%class%">\
-            <td colspan="3" style="text-align: center;">%text%</td>\
+            '<tr class="%class%">\\
+            <td colspan="3" style="text-align: center;">%text%</td>\\
             </tr>'
     );
 </script>
diff --git a/tests/test-command-template.t b/tests/test-command-template.t
index 99c4b8f79324ad2ca00bf08228c87a2b40cec2af_dGVzdHMvdGVzdC1jb21tYW5kLXRlbXBsYXRlLnQ=..64b4f0cd73369185656a36ab8823f1ac082d1d23_dGVzdHMvdGVzdC1jb21tYW5kLXRlbXBsYXRlLnQ= 100644
--- a/tests/test-command-template.t
+++ b/tests/test-command-template.t
@@ -1586,3 +1586,11 @@
   h1c
   b
   a
+
+Test string escaping:
+
+  $ hg log -R latesttag -r 0 --template '>\n<>\\n<{if(rev, "[>\n<>\\n<]")}>\n<>\\n<\n'
+  >
+  <>\n<[>
+  <>\n<]>
+  <>\n<