[pypy-commit] pypy fastjson: add two tests and the corresponding fixes

antocuni noreply at buildbot.pypy.org
Wed Jun 5 16:52:44 CEST 2013


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: fastjson
Changeset: r64800:ca39af17b48f
Date: 2013-06-05 15:56 +0200
http://bitbucket.org/pypy/pypy/changeset/ca39af17b48f/

Log:	add two tests and the corresponding fixes

diff --git a/pypy/module/_fastjson/interp_decoder.py b/pypy/module/_fastjson/interp_decoder.py
--- a/pypy/module/_fastjson/interp_decoder.py
+++ b/pypy/module/_fastjson/interp_decoder.py
@@ -177,7 +177,9 @@
             if self.last_type != TYPE_STRING:
                 self._raise("Key name must be string for object starting at char %d", start)
             self.skip_whitespace()
-            ch = self.next() # XXX
+            if self.eof():
+                break
+            ch = self.next()
             if ch != ':':
                 self._raise("No ':' found at char %d", self.i)
             self.skip_whitespace()
@@ -185,6 +187,8 @@
             w_value = self.decode_any()
             self.space.setitem(w_dict, w_name, w_value)
             self.skip_whitespace()
+            if self.eof():
+                break
             ch = self.next()
             if ch == '}':
                 return w_dict
diff --git a/pypy/module/_fastjson/test/test__fastjson.py b/pypy/module/_fastjson/test/test__fastjson.py
--- a/pypy/module/_fastjson/test/test__fastjson.py
+++ b/pypy/module/_fastjson/test/test__fastjson.py
@@ -104,6 +104,8 @@
         s = '{"hello": "world", "aaa": "bbb"}'
         assert _fastjson.loads(s) == {'hello': 'world',
                                       'aaa': 'bbb'}
+        raises(ValueError, _fastjson.loads, '{"key"')
+        raises(ValueError, _fastjson.loads, '{"key": 42')
 
     def test_decode_object_nonstring_key(self):
         import _fastjson


More information about the pypy-commit mailing list