Skip to content

Numbers with extra prefix 0 should not be accepted as valid input #591

Open

Description

@MichaelSuen-thePointer

What did you do?

ujson.loads("0012")

What did you expect to happen?

exception raised, ValueError for example

What actually happened?

function returns 12

What versions are you using?

  • OS: Debian 10
  • Python: 3.7.3
  • UltraJSON: 5.7.0

Please include code that reproduces the issue.

The best reproductions are self-contained scripts with minimal dependencies.

try:
    ujson.loads("0012")
    print("not ok")
except ValueError:
    print("ok")

Activity

  1. bwoodsend commented on May 17, 2023

    @bwoodsend
    Collaborator

    The JSON spec explicitly allows parsers to accept input that isn't part of the spec but whose intention is clear and non ambiguous.

    Beyond purism, why does this actually matter?

  2. MichaelSuen-thePointer commented on May 17, 2023

    @MichaelSuen-thePointer
    Author

    The JSON spec explicitly allows parsers to accept input that isn't part of the spec but whose intention is clear and non ambiguous.

    Beyond purism, why does this actually matter?

    I was porting code from python standard json to ujson for better performance, and the code relies on loads("0012") to fail.

  3. bwoodsend commented on May 17, 2023

    @bwoodsend
    Collaborator

    You're probably better off going with orjson then. They take the opposite stance to us on accepting non standard inputs.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions