[issue15393] JSONDecoder.raw_decode breaks on leading whitespace

2012-07-20 Thread Antti Laine

Antti Laine  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 
<http://bugs.python.org/issue15393>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15393] JSONDecoder.raw_decode breaks on leading whitespace

2012-07-19 Thread Antti Laine

Antti Laine  added the comment:

Suggestion for a patch for 3.3.0. I wasn't quite sure how the testcases were 
supposed to be loaded. Sorry if I made a mess ;)

--
keywords: +patch
Added file: 
http://bugs.python.org/file26434/json-raw-decoder-fix-whitespace.diff

___
Python tracker 
<http://bugs.python.org/issue15393>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15393] JSONDecoder.raw_decode breaks on leading whitespace

2012-07-19 Thread Antti Laine

Antti Laine  added the comment:

My coworker just submitted a pull request for a possible fix to simplejson on 
github.

https://github.com/simplejson/simplejson/pull/38

--

___
Python tracker 
<http://bugs.python.org/issue15393>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15393] JSONDecoder.raw_decode breaks on leading whitespace

2012-07-19 Thread Antti Laine

New submission from Antti Laine :

raw_decode on json.JSONDecoder does not handle leading whitespace. According to 
RFC 4627, section 2, whitespace can precede an object. With json.loads leading 
whitespace is handled just fine.

d = json.JSONDecoder()
d.raw_decode(' {}')
ValueError: No JSON object could be decoded

Tested with versions 2.6.7, 2.7.3, 3.1.3 and 3.2.3

--
components: Library (Lib)
messages: 165829
nosy: Antti Alien
priority: normal
severity: normal
status: open
title: JSONDecoder.raw_decode breaks on leading whitespace
type: behavior
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2

___
Python tracker 
<http://bugs.python.org/issue15393>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com