Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix encoding of infinity (#80). #562

Merged
merged 2 commits into from Aug 8, 2022
Merged

Fix encoding of infinity (#80). #562

merged 2 commits into from Aug 8, 2022

Conversation

bwoodsend
Copy link
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

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
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
Member

hugovk commented Aug 7, 2022

GitHub tip:

Add something like "Fixes #80" in the PR message and it'll autoclose the issue when merged:

https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests

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
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
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
Collaborator Author

There we go. Even precommit is happy 🙄

@bwoodsend bwoodsend requested a review from hugovk August 8, 2022 18:33
Copy link
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!

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