Mercurial > hg
changeset 27881:ffa599f3f503
encoding: escape U+007F (DEL) character in JSON
RFC 7159 does not state that U+007F must be escaped, but it is widely
considered a control character. As '\x7f' is invisible on a terminal, and
Python's json.dumps() escapes '\x7f', let's do the same.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 16 Jan 2016 18:30:01 +0900 |
parents | b04df9ce1fb0 |
children | 319b0bf6ecc9 |
files | mercurial/encoding.py |
diffstat | 1 files changed, 5 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/encoding.py Thu Jan 14 04:14:50 2016 +0000 +++ b/mercurial/encoding.py Sat Jan 16 18:30:01 2016 +0900 @@ -395,8 +395,10 @@ >>> jsonescape('this is a test') 'this is a test' - >>> jsonescape('escape characters: \\0 \\x0b \\t \\n \\r \\" \\\\') - 'escape characters: \\\\u0000 \\\\u000b \\\\t \\\\n \\\\r \\\\" \\\\\\\\' + >>> jsonescape('escape characters: \\0 \\x0b \\x7f') + 'escape characters: \\\\u0000 \\\\u000b \\\\u007f' + >>> jsonescape('escape characters: \\t \\n \\r \\" \\\\') + 'escape characters: \\\\t \\\\n \\\\r \\\\" \\\\\\\\' >>> jsonescape('a weird byte: \\xdd') 'a weird byte: \\xed\\xb3\\x9d' >>> jsonescape('utf-8: caf\\xc3\\xa9') @@ -411,6 +413,7 @@ for x in xrange(32, 256): c = chr(x) _jsonmap[c] = c + _jsonmap['\x7f'] = '\\u007f' _jsonmap['\t'] = '\\t' _jsonmap['\n'] = '\\n' _jsonmap['\"'] = '\\"'