[PATCH 1 of 1 stable] templatefilters: fix json filter not to convert character encoding
Yuya Nishihara
yuya at tcha.org
Mon Aug 9 11:39:15 CDT 2010
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1281371512 -32400
# Branch stable
# Node ID a0a65c04bc25a27f8d0331380735fac8a1e683d2
# Parent ca6cebd8734e625086d41c6eb90aa9714bd5970b
templatefilters: fix json filter not to convert character encoding
JSON filter is used by hgweb to generate graph data. Its encoding is
specified by encoding.encoding. (regression of aff419e260f9)
diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py
--- a/mercurial/templatefilters.py
+++ b/mercurial/templatefilters.py
@@ -157,7 +157,7 @@ def json(obj):
return str(obj)
elif isinstance(obj, str):
u = unicode(obj, encoding.encoding, 'replace')
- return '"%s"' % jsonescape(u).encode('utf-8')
+ return '"%s"' % jsonescape(u).encode(encoding.encoding, 'replace')
elif isinstance(obj, unicode):
return '"%s"' % jsonescape(obj).encode('utf-8')
elif hasattr(obj, 'keys'):
diff --git a/tests/test-hgweb-commands.out b/tests/test-hgweb-commands.out
--- a/tests/test-hgweb-commands.out
+++ b/tests/test-hgweb-commands.out
@@ -984,5 +984,5 @@ ul#graphnodes li .info {
}
% Stop and restart with HGENCODING=cp932
% Graph json escape of multibyte character
-var data = [["40b4d6888e92", [0, 1], [[0, 0, 1]], "è½", "test", "1970-01-01", ["stable", true], ["tip"]], ["1d22e65f027e", [0, 1], [[0, 0, 1]], "branch", "test", "1970-01-01", ["stable", false], []], ["a4f92ed23982", [0, 1], [[0, 0, 1]], "Added tag 1.0 for changeset 2ef0ac749a14", "test", "1970-01-01", ["default", true], []], ["2ef0ac749a14", [0, 1], [], "base", "test", "1970-01-01", ["default", false], ["1.0"]]];
+var data = [["40b4d6888e92", [0, 1], [[0, 0, 1]], "\", "test", "1970-01-01", ["stable", true], ["tip"]], ["1d22e65f027e", [0, 1], [[0, 0, 1]], "branch", "test", "1970-01-01", ["stable", false], []], ["a4f92ed23982", [0, 1], [[0, 0, 1]], "Added tag 1.0 for changeset 2ef0ac749a14", "test", "1970-01-01", ["default", true], []], ["2ef0ac749a14", [0, 1], [], "base", "test", "1970-01-01", ["default", false], ["1.0"]]];
% ERRORS ENCOUNTERED
More information about the Mercurial-devel
mailing list