Browse files

Allow leading zeroes in exponent part of numbers

  • Loading branch information...
1 parent b1645ee commit 7c11174012d60d60a76bbffa429dd4c618c6f71e @udp committed Dec 9, 2012
Showing with 30 additions and 12 deletions.
  1. +10 −8 json.c
  2. +0 −1 tests/invalid-0007.json
  3. +12 −3 tests/test.py
  4. +8 −0 tests/valid-0008.json
View
18 json.c
@@ -572,15 +572,17 @@ json_value * json_parse_ex (json_settings * settings, const json_char * json, ch
if (top->type == json_integer || flags & flag_num_e)
{
- if (flags & flag_num_zero)
- { sprintf (error, "%d:%d: Unexpected `0` before `%c`", cur_line, e_off, b);
- goto e_failed;
- }
-
- if (num_digits == 1 && b == '0')
- flags |= flag_num_zero;
+ if (! (flags & flag_num_e))
+ {
+ if (flags & flag_num_zero)
+ { sprintf (error, "%d:%d: Unexpected `0` before `%c`", cur_line, e_off, b);
+ goto e_failed;
+ }
- if (flags & flag_num_e)
+ if (num_digits == 1 && b == '0')
+ flags |= flag_num_zero;
+ }
+ else
{
flags |= flag_num_e_got_sign;
num_e = (num_e * 10) + (b - '0');
View
1 tests/invalid-0007.json
@@ -1 +0,0 @@
--1.0e-048
View
15 tests/test.py
@@ -9,15 +9,24 @@
failed = "\033[91mFailed\033[0m"
for i, test in enumerate(
- map(lambda file: json.loads(open(file).read()), sorted(glob.glob('valid*.json')))):
+ map(lambda file: open(file).read(), sorted(glob.glob('valid*.json')))):
try:
- reencoded = jsonparser.decode(json.dumps(test))
+ jsonparser.decode(test)
except jsonparser.JSONException as error:
print 'valid/%d : Failed with error: %s' % (i, error)
continue
- if reencoded != test:
+ py_decoded = json.loads(test)
+ py_reencoded = json.dumps(py_decoded)
+
+ try:
+ reencoded = jsonparser.decode(py_reencoded)
+ except jsonparser.JSONException as error:
+ print 'valid/%d : Failed on re-encoded version with error: %s' % (i, error)
+ continue
+
+ if reencoded != py_decoded:
print 'valid/%d : %s:\n\n%s\n\nbecame\n\n%s\n' % (i, failed, test, reencoded)
else:
print 'valid/%d : %s' % (i, passed)
View
8 tests/valid-0008.json
@@ -0,0 +1,8 @@
+[
+ 0.4e006,
+ 0.4e-006,
+ 0.4e+006,
+ 4e006,
+ 4e-006,
+ 4e+006
+]

0 comments on commit 7c11174

Please sign in to comment.