changeset 32742:08d0892c93d8

json: avoid extra string manipulation of dict keys A key must be string per JSON spec, and that's also true for template dicts.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 23 Apr 2017 13:40:18 +0900
parents 8f83f924ee1c
children f924dd043974
files mercurial/templatefilters.py
diffstat 1 files changed, 1 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templatefilters.py	Fri Jun 09 21:45:22 2017 +0900
+++ b/mercurial/templatefilters.py	Sun Apr 23 13:40:18 2017 +0900
@@ -234,7 +234,7 @@
     elif isinstance(obj, bytes):
         return '"%s"' % encoding.jsonescape(obj, paranoid=paranoid)
     elif util.safehasattr(obj, 'keys'):
-        out = ['%s: %s' % (json(k), json(v))
+        out = ['"%s": %s' % (encoding.jsonescape(k, paranoid=paranoid), json(v))
                for k, v in sorted(obj.iteritems())]
         return '{' + ', '.join(out) + '}'
     elif util.safehasattr(obj, '__iter__'):