[New-bugs-announce] [issue21194] json.dumps with ensure_ascii=False doesn't escape control characters
Weeble
report at bugs.python.org
Thu Apr 10 11:31:10 CEST 2014
New submission from Weeble:
The JSON spec (http://www.json.org/) does not allow unescaped control characters. (See the railroad diagram for strings and the grammar on the right.) If json.dumps is called with ensure_ascii=False, it fails to escape control codes in the range U+007F to U+009F. Here's an example:
>>> import json
>>> import unicodedata
>>> for i in range(256):
... jsonstring = json.dumps(chr(i), ensure_ascii=False)
... if any(unicodedata.category(ch) == 'Cc' for ch in jsonstring):
... print("Fail:",repr(chr(i)))
Fail: '\x7f'
Fail: '\x80'
Fail: '\x81'
Fail: '\x82'
Fail: '\x83'
Fail: '\x84'
Fail: '\x85'
Fail: '\x86'
Fail: '\x87'
Fail: '\x88'
Fail: '\x89'
Fail: '\x8a'
Fail: '\x8b'
Fail: '\x8c'
Fail: '\x8d'
Fail: '\x8e'
Fail: '\x8f'
Fail: '\x90'
Fail: '\x91'
Fail: '\x92'
Fail: '\x93'
Fail: '\x94'
Fail: '\x95'
Fail: '\x96'
Fail: '\x97'
Fail: '\x98'
Fail: '\x99'
Fail: '\x9a'
Fail: '\x9b'
Fail: '\x9c'
Fail: '\x9d'
Fail: '\x9e'
Fail: '\x9f'
----------
components: Library (Lib)
messages: 215868
nosy: weeble
priority: normal
severity: normal
status: open
title: json.dumps with ensure_ascii=False doesn't escape control characters
type: behavior
versions: Python 3.4
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21194>
_______________________________________
More information about the New-bugs-announce
mailing list