diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py --- a/mercurial/templatefilters.py +++ b/mercurial/templatefilters.py @@ -106,12 +106,17 @@ def basename(path): return os.path.basename(path) +def _tocborencodable(obj): + if isinstance(obj, smartset.abstractsmartset): + return list(obj) + return obj + + @templatefilter(b'cbor') def cbor(obj): """Any object. Serializes the object to CBOR bytes.""" - if isinstance(obj, smartset.abstractsmartset): - # cborutil is stricter about type than json() filter - obj = list(obj) + # cborutil is stricter about type than json() filter + obj = pycompat.rapply(_tocborencodable, obj) return b''.join(cborutil.streamencode(obj)) diff --git a/tests/test-template-functions.t b/tests/test-template-functions.t --- a/tests/test-template-functions.t +++ b/tests/test-template-functions.t @@ -1616,6 +1616,15 @@ Test cbor filter: ] ] + $ hg log -T "{dict(foo=revset('.'))|cbor}" -R a -l1 | "$PYTHON" "$TESTTMP/decodecbor.py" + [ + { + 'foo': [ + 10 + ] + } + ] + json filter should escape HTML tags so that the output can be embedded in hgweb: $ hg log -T "{''|json}\n" -R a -l1