[pypy-commit] pypy fastjson: the only number which is allowed to start with 0 is 0 itself

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


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: fastjson
Changeset: r65048:6e71ab1760e1
Date: 2013-06-26 14:32 +0200
http://bitbucket.org/pypy/pypy/changeset/6e71ab1760e1/

Log:	the only number which is allowed to start with 0 is 0 itself

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
@@ -154,6 +154,9 @@
             i += 1
         elif self.ll_chars[i] == '+':
             i += 1
+        elif self.ll_chars[i] == '0':
+            i += 1
+            return i, 0
         i, intval, _ = self.parse_digits(i)
         return i, sign * intval
 
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
@@ -113,6 +113,10 @@
         check('42E-1', 4.2)
         check('42E+1', 420.0)
         check('42.123E3', 42123.0)
+        check('0', 0)
+        check('-0', 0)
+        check('0.123', 0.123)
+        check('0E3', 0.0)
 
     def test_decode_numeric_invalid(self):
         import _fastjson
@@ -125,6 +129,7 @@
         error('12.-3')
         error('12E')
         error('12E-')
+        error('0123') # numbers can't start with 0
 
     def test_decode_object(self):
         import _fastjson


More information about the pypy-commit mailing list