Skip to content

Fix encoding of infinity (#80).#562

Merged
bwoodsend merged 2 commits intoultrajson:mainfrom
bwoodsend:inf
Aug 8, 2022
Merged

Fix encoding of infinity (#80).#562
bwoodsend merged 2 commits intoultrajson:mainfrom
bwoodsend:inf

Conversation

@bwoodsend
Copy link
Copy Markdown
Collaborator

Infinity was being encoded as 'Inf' which, whilst the JSON spec doesn't include any non-finite floats, differs from the conventions in other JSON libraries, JavaScript of using 'Infinity'. It also differs from what ujson.loads() expects so that ujson.loads(ujson.dumps(math.inf)) raises an exception.

@bwoodsend bwoodsend added the changelog: Fixed For any bug fixes label Aug 6, 2022
@bwoodsend bwoodsend linked an issue Aug 6, 2022 that may be closed by this pull request
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Aug 6, 2022

Codecov Report

Merging #562 (8c15f18) into main (bcdc041) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main     #562   +/-   ##
=======================================
  Coverage   91.58%   91.58%           
=======================================
  Files           6        6           
  Lines        1901     1901           
=======================================
  Hits         1741     1741           
  Misses        160      160           
Impacted Files Coverage Δ
python/ujson.c 70.73% <ø> (ø)
tests/test_ujson.py 99.45% <ø> (ø)
python/objToJSON.c 88.77% <100.00%> (ø)

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

Copy link
Copy Markdown
Collaborator

@JustAnotherArchivist JustAnotherArchivist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ENCODER_HELP_TEXT in python/ujson.c should probably get an s/Inf/Infinity/ as well. LGTM otherwise.

@hugovk
Copy link
Copy Markdown
Member

hugovk commented Aug 7, 2022

Infinity was being encoded as 'Inf' which, whilst the JSON spec doesn't include
any non-finite floats, differs from the conventions in other JSON libraries,
JavaScript of using 'Infinity'. It also differs from what `ujson.loads()`
expects so that `ujson.loads(ujson.dumps(math.inf))` raises an exception.

Closes ultrajson#80.
@bwoodsend
Copy link
Copy Markdown
Collaborator Author

Ughh, how do you put up with these precommit hooks. This one essentially reverts us back to the deprecated behaviour I was trying to fix.

@hugovk
Copy link
Copy Markdown
Member

hugovk commented Aug 7, 2022

Yeah, if 854597d is a problem, we can remove/comment out setup-cfg-fmt from .pre-commit-config.yaml for now, because they don't want to switch to license_files yet:

asottile/setup-cfg-fmt#73

@bwoodsend
Copy link
Copy Markdown
Collaborator Author

There we go. Even precommit is happy 🙄

@bwoodsend bwoodsend requested a review from hugovk August 8, 2022 18:33
Copy link
Copy Markdown
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you!

@bwoodsend bwoodsend merged commit 203f311 into ultrajson:main Aug 8, 2022
@bwoodsend bwoodsend deleted the inf branch August 8, 2022 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog: Fixed For any bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Infinity handling differs to python native json

4 participants