Mercurial > public > mercurial-scm > hg-stable
diff mercurial/templatefilters.py @ 11765:aff419e260f9 stable
templatefilters: make json filter handle multibyte characters correctly
It aims to fix javascript error of hgweb's graph view in Japanese 'cp932'
encoding.
'cp932' contains multibyte characters ending with '\x5c' (backslash),
e.g. '\x94\x5c' for Japanese Kanji 'Noh'.
Due to json filter escapes '\' to '\\', multibyte string ending with
'\x5c' is translated to "xxx\", resulting javascript parse error on
a web browser.
This patch changes json() to pass unicode to jsonescape().
Unicode decoding error handler changed to 'replace' by Patrick M?zard.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 07 Aug 2010 16:27:16 +0900 |
parents | d320e70442a5 |
children | 9dac951d0185 |
line wrap: on
line diff
--- a/mercurial/templatefilters.py Fri Aug 06 12:18:33 2010 -0500 +++ b/mercurial/templatefilters.py Sat Aug 07 16:27:16 2010 +0900 @@ -156,9 +156,10 @@ elif isinstance(obj, int) or isinstance(obj, float): return str(obj) elif isinstance(obj, str): - return '"%s"' % jsonescape(obj) + u = unicode(obj, encoding.encoding, 'replace') + return '"%s"' % jsonescape(u).encode('utf-8') elif isinstance(obj, unicode): - return json(obj.encode('utf-8')) + return '"%s"' % jsonescape(obj).encode('utf-8') elif hasattr(obj, 'keys'): out = [] for k, v in obj.iteritems():