json: avoid extra string manipulation of dict keys
authorYuya Nishihara <yuya@tcha.org>
Sun, 23 Apr 2017 13:40:18 +0900
changeset 32742 08d0892c93d8
parent 32741 8f83f924ee1c
child 32743 f924dd043974
json: avoid extra string manipulation of dict keys A key must be string per JSON spec, and that's also true for template dicts.
mercurial/templatefilters.py
--- 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__'):