Skip to content

Scanner accepts JSON numbers with leading zeros #2

Description

@whyvineet

The JSON scanner currently accepts numbers with leading zeros, such as 01 and 007.

These are not valid JSON numbers. According to the JSON number grammar, an integer component must be either exactly 0 or start with a non-zero digit followed by additional digits.

json.loads() correctly rejects these documents, but bytejson currently indexes them successfully and may return the parsed value during per-leaf access.

Reproduction

import bytejson

open("./tmp/leadzero.json", "w").write('{"n": 007}')

db = bytejson.open("./tmp/leadzero.json")
print(db["n"])

Observed:

7

The document is therefore accepted and interpreted as valid JSON.

Activity

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions