[pypy-commit] pypy fastjson: handle another not-so-corner case: an object with spaces inside

antocuni noreply at buildbot.pypy.org
Fri Jun 28 16:28:12 CEST 2013


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: fastjson
Changeset: r65069:31fc5dae889c
Date: 2013-06-28 16:00 +0200
http://bitbucket.org/pypy/pypy/changeset/31fc5dae889c/

Log:	handle another not-so-corner case: an object with spaces inside

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
@@ -265,12 +265,14 @@
     def decode_object(self, i):
         start = i
         w_dict = self.space.newdict()
+        #
+        i = self.skip_whitespace(i)
+        ch = self.ll_chars[i]
+        if ch == '}':
+            self.pos = i+1
+            return w_dict
+
         while True:
-            ch = self.ll_chars[i]
-            if ch == '}':
-                self.pos = i+1
-                return w_dict
-            #
             # parse a key: value
             self.last_type = TYPE_UNKNOWN
             w_name = self.decode_any(i)
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
@@ -146,6 +146,7 @@
     def test_decode_object(self):
         import _fastjson
         assert _fastjson.loads('{}') == {}
+        assert _fastjson.loads('{  }') == {}
         #
         s = '{"hello": "world", "aaa": "bbb"}'
         assert _fastjson.loads(s) == {'hello': 'world',
@@ -172,3 +173,4 @@
         res = _fastjson.loads('"z\\ud834\\udd20x"')
         assert res == expected
 
+


More information about the pypy-commit mailing list