ultrajson icon indicating copy to clipboard operation
ultrajson copied to clipboard

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

Open MichaelSuen-thePointer opened this issue 2 years ago • 3 comments

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")

MichaelSuen-thePointer avatar May 17 '23 09:05 MichaelSuen-thePointer

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?

bwoodsend avatar May 17 '23 13:05 bwoodsend

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.

MichaelSuen-thePointer avatar May 17 '23 14:05 MichaelSuen-thePointer

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

bwoodsend avatar May 17 '23 18:05 bwoodsend