changeset 28687:29c249dfb4ef

templater: do not strip non-quote characters from template config Before this patch, the first and last characters were stripped from ui.logtemplate and template.* if they were the same. It could lead to a strange result as quotes are optional. See the test for example.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 27 Mar 2016 17:42:19 +0900
parents b212e01fead0
children 3e0d03c3c594
files mercurial/templater.py tests/test-command-template.t
diffstat 2 files changed, 3 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templater.py	Tue Mar 29 11:50:41 2016 -0700
+++ b/mercurial/templater.py	Sun Mar 27 17:42:19 2016 +0900
@@ -868,7 +868,7 @@
 
 def unquotestring(s):
     '''unwrap quotes if any; otherwise returns unmodified string'''
-    if len(s) < 2 or s[0] != s[-1]:
+    if len(s) < 2 or s[0] not in "'\"" or s[0] != s[-1]:
         return s
     return s[1:-1]
 
--- a/tests/test-command-template.t	Tue Mar 29 11:50:41 2016 -0700
+++ b/tests/test-command-template.t	Sun Mar 27 17:42:19 2016 +0900
@@ -71,6 +71,8 @@
   8
   $ hg tip --config 'ui.logtemplate="{rev}\n"'
   8
+  $ hg tip --config 'ui.logtemplate=n{rev}\n'
+  n8
 
 Make sure user/global hgrc does not affect tests