[issue15393] JSONDecoder.raw_decode breaks on leading whitespace

Antti Laine report at bugs.python.org
Fri Jul 20 14:42:00 CEST 2012


Antti Laine <antti.a.laine at iki.fi> added the comment:

> you are changing the signature of "decode()" and that would be a compatibility problem

I was changing the signature of raw_decode(), by adding a(n almost) private keyword. I really don't see how that would affect compatibility.

> you are thinking that "json document" includes the possibility of leading whitespace

Yes. While JSON does not have a real standard to follow, I believe that going by the RFC is the best thing to do, and the RFC very clearly states, that objects can be surrounded with whitespace.

decode() depends on the functionality of raw_decode(), and its own parameter _w. I have no idea why _w is a parameter. It is not used anywhere in CPython, and, beginning with an underscore, it shouldn't be used from anywhere else. Still it offers the users a possibility to break the behaviour of decode(). If it's a performance hack, making the variable being initialized only once, then I think it's a very poor one.

Now the patch leaves decode() as it is, and checks for whitespace in raw_decode(), which leads to checking for whitespace twice when using decode().

I think that a more extensive cleanup would be in order.

----------
Added file: http://bugs.python.org/file26450/json-raw-decoder-fix-whitespace.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15393>
_______________________________________


More information about the Python-bugs-list mailing list