diff mercurial/templatekw.py @ 36634:cafd0586876b

templater: byte-stringify dict/list values before passing to default format bytestr() is applied only when no custom format string like '%d' is specified.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 01 Mar 2018 08:14:54 -0500
parents 034a07e60e98
children 32f9b7e3f056
line wrap: on
line diff
--- a/mercurial/templatekw.py	Thu Mar 01 08:07:22 2018 -0500
+++ b/mercurial/templatekw.py	Thu Mar 01 08:14:54 2018 -0500
@@ -99,16 +99,20 @@
 
 def hybriddict(data, key='key', value='value', fmt=None, gen=None):
     """Wrap data to support both dict-like and string-like operations"""
+    prefmt = pycompat.identity
     if fmt is None:
         fmt = '%s=%s'
+        prefmt = pycompat.bytestr
     return _hybrid(gen, data, lambda k: {key: k, value: data[k]},
-                   lambda k: fmt % (k, data[k]))
+                   lambda k: fmt % (prefmt(k), prefmt(data[k])))
 
 def hybridlist(data, name, fmt=None, gen=None):
     """Wrap data to support both list-like and string-like operations"""
+    prefmt = pycompat.identity
     if fmt is None:
         fmt = '%s'
-    return _hybrid(gen, data, lambda x: {name: x}, lambda x: fmt % x)
+        prefmt = pycompat.bytestr
+    return _hybrid(gen, data, lambda x: {name: x}, lambda x: fmt % prefmt(x))
 
 def unwraphybrid(thing):
     """Return an object which can be stringified possibly by using a legacy