[pypy-commit] pypy fastjson: leading 0s are allowed in the exponent part

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


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

Log:	leading 0s are allowed in the exponent part

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
@@ -117,7 +117,7 @@
         self._raise("Error when decoding false at char %d", i)
 
     def decode_numeric(self, i):
-        i, intval = self.parse_integer(i)
+        i, intval = self.parse_integer(i, allow_leading_0=False)
         #
         is_float = False
         exp = 0
@@ -134,7 +134,7 @@
         # check for the optional exponent part
         if ch == 'E' or ch == 'e':
             is_float = True
-            i, exp = self.parse_integer(i+1)
+            i, exp = self.parse_integer(i+1, allow_leading_0=True)
         #
         self.pos = i
         if is_float:
@@ -146,7 +146,7 @@
         else:
             return self.space.wrap(intval)
 
-    def parse_integer(self, i):
+    def parse_integer(self, i, allow_leading_0=False):
         "Parse a decimal number with an optional minus sign"
         sign = 1
         if self.ll_chars[i] == '-':
@@ -154,7 +154,7 @@
             i += 1
         elif self.ll_chars[i] == '+':
             i += 1
-        elif self.ll_chars[i] == '0':
+        elif not allow_leading_0 and self.ll_chars[i] == '0':
             i += 1
             return i, 0
         i, intval, _ = self.parse_digits(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
@@ -117,6 +117,7 @@
         check('-0', 0)
         check('0.123', 0.123)
         check('0E3', 0.0)
+        check('5E0001', 50.0)
 
     def test_decode_numeric_invalid(self):
         import _fastjson
@@ -125,6 +126,7 @@
         #
         error('  42   abc')
         error('.123')
+        error('+123')
         error('12.')
         error('12.-3')
         error('12E')


More information about the pypy-commit mailing list