# HG changeset patch # User Bob Ippolito <bob@redivi.com> # Date 1288603871 0 # Mon Nov 01 09:31:11 2010 +0000 # Node ID 86cdc91f93e9d71e68e9c35c331bd6dd41ccec00 # Parent f0db3c5e1e0f99b3a64d1f0edcb34482072b1a4a re http://code.google.com/p/simplejson/issues/detail?id=85 git-svn-id: http://simplejson.googlecode.com/svn/trunk@236 a4795897-2c25-0410-b006-0d3caba88fa1 diff --git a/CHANGES.txt b/CHANGES.txt --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,5 +1,7 @@ Version 2.1.2 released XXXX-XX-XX +* Correct wrong end when object_pairs_hook is used + http://code.google.com/p/simplejson/issues/detail?id=85 * Correct output for indent=0 http://bugs.python.org/issue10019 * Correctly raise TypeError when non-string keys are used with speedups diff --git a/simplejson/decoder.py b/simplejson/decoder.py --- a/simplejson/decoder.py +++ b/simplejson/decoder.py @@ -31,7 +31,7 @@ class JSONDecodeError(ValueError): """Subclass of ValueError with the following additional properties: - + msg: The unformatted error message doc: The JSON document being parsed pos: The start index of doc where parsing failed @@ -40,7 +40,7 @@ colno: The column corresponding to pos endlineno: The line corresponding to end (may be None) endcolno: The column corresponding to end (may be None) - + """ def __init__(self, msg, doc, pos, end=None): ValueError.__init__(self, errmsg(msg, doc, pos, end=end)) @@ -197,7 +197,7 @@ if nextchar == '}': if object_pairs_hook is not None: result = object_pairs_hook(pairs) - return result, end + return result, end + 1 pairs = {} if object_hook is not None: pairs = object_hook(pairs) diff --git a/simplejson/tests/test_decode.py b/simplejson/tests/test_decode.py --- a/simplejson/tests/test_decode.py +++ b/simplejson/tests/test_decode.py @@ -71,3 +71,13 @@ self.assertEqual(json.loads(u'""'), u"") self.assertEqual(json.loads('[""]'), [""]) self.assertEqual(json.loads(u'[""]'), [u""]) + + def test_raw_decode(self): + cls = json.decoder.JSONDecoder + self.assertEqual( + ({'a': {}}, 9), + cls().raw_decode("{\"a\": {}}")) + # http://code.google.com/p/simplejson/issues/detail?id=85 + self.assertEqual( + ({'a': {}}, 9), + cls(object_pairs_hook=dict).raw_decode("{\"a\": {}}"))