Skip to content

Accept zero with an exponent and reject an empty number - #232

Open
emincan2000 wants to merge 1 commit into
kgabis:masterfrom
emincan2000:number-zero-exponent
Open

emincan2000 wants to merge 1 commit into
kgabis:masterfrom
emincan2000:number-zero-exponent

Conversation

@emincan2000

Copy link
Copy Markdown

is_decimal rejects numbers starting with 0 unless a dot follows, so valid JSON like 0e5, 0E+5 and -0e-5 fails to parse. It now rejects a leading zero only when another digit follows.

It also accepts a lone minus. strtod converts nothing, the length is 0, and json_parse_string("-") returns the number 0. The same happens for --1 and -e5. Empty numbers are now rejected.

I added cases to test_suite_3 that fail on master. make test, testcpp and test_hash_collisions all pass with the fix. I also compared old and new builds on about 62k inputs under ASan and UBSan, using Python's json module to distinguish valid from invalid inputs: no valid input became rejected. Trailing characters at the top level are still ignored, so 0e5, parses the same way 1e5, does.

is_decimal rejected valid numbers like 0e5 because it wanted a dot after
a leading zero. It also accepted a lone minus, where strtod converts
nothing, and parsed it as 0.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant