Patchwork [4,of,4] json: pass formatting options recursively

login
register
mail settings
Submitter Yuya Nishihara
Date June 9, 2017, 2:42 p.m.
Message ID <8089aac37fad98442ba2.1497019377@mimosa>
Download mbox | patch
Permalink /patch/21288/
State Accepted
Headers show

Comments

Yuya Nishihara - June 9, 2017, 2:42 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1497011595 -32400
#      Fri Jun 09 21:33:15 2017 +0900
# Node ID 8089aac37fad98442ba210f95f8fec8599dc9f03
# Parent  cfed8eb80946df2022a945708a9ae38e02768696
json: pass formatting options recursively

This bug was introduced in 654e9a1c8a6c. It's okay to escape <>, but is
unnecessary for command output.
Augie Fackler - June 9, 2017, 6:10 p.m.
On Fri, Jun 09, 2017 at 11:42:57PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1497011595 -32400
> #      Fri Jun 09 21:33:15 2017 +0900
> # Node ID 8089aac37fad98442ba210f95f8fec8599dc9f03
> # Parent  cfed8eb80946df2022a945708a9ae38e02768696
> json: pass formatting options recursively

queued, thanks

Patch

diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py
--- a/mercurial/templatefilters.py
+++ b/mercurial/templatefilters.py
@@ -234,11 +234,12 @@  def json(obj, paranoid=True):
     elif isinstance(obj, bytes):
         return '"%s"' % encoding.jsonescape(obj, paranoid=paranoid)
     elif util.safehasattr(obj, 'keys'):
-        out = ['"%s": %s' % (encoding.jsonescape(k, paranoid=paranoid), json(v))
+        out = ['"%s": %s' % (encoding.jsonescape(k, paranoid=paranoid),
+                             json(v, paranoid))
                for k, v in sorted(obj.iteritems())]
         return '{' + ', '.join(out) + '}'
     elif util.safehasattr(obj, '__iter__'):
-        out = [json(i) for i in obj]
+        out = [json(i, paranoid) for i in obj]
         return '[' + ', '.join(out) + ']'
     else:
         raise TypeError('cannot encode type %s' % obj.__class__.__name__)
diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
--- a/tests/test-obsolete.t
+++ b/tests/test-obsolete.t
@@ -739,7 +739,7 @@  List of all markers in JSON
    {
     "date": *, (glob)
     "flag": 0,
-    "metadata": {"user": "test \u003ctest@example.net\u003e"},
+    "metadata": {"user": "test <test@example.net>"},
     "precnode": "cda648ca50f50482b7055c0b0c4c117bba6733d9",
     "succnodes": ["3de5eca88c00aa039da7399a220f4a5221faa585"]
    }