[PATCH 3 of 4] json: avoid extra string manipulation of dict keys
Yuya Nishihara
yuya at tcha.org
Fri Jun 9 10:42:56 EDT 2017
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1492922418 -32400
# Sun Apr 23 13:40:18 2017 +0900
# Node ID cfed8eb80946df2022a945708a9ae38e02768696
# Parent b919b4f2cf8c55367764d3b2b323e9b64bae6a4e
json: avoid extra string manipulation of dict keys
A key must be string per JSON spec, and that's also true for template dicts.
diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py
--- a/mercurial/templatefilters.py
+++ b/mercurial/templatefilters.py
@@ -234,7 +234,7 @@ def json(obj, paranoid=True):
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__'):
More information about the Mercurial-devel
mailing list