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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ repos:
- id: trailing-whitespace
exclude: "^.github/.*_TEMPLATE.md"

- repo: https://github.com/asottile/setup-cfg-fmt
rev: v1.20.1
hooks:
- id: setup-cfg-fmt
# Disabled due to asottile/setup-cfg-fmt#73. Re-enable once that issue is fixed.
# - repo: https://github.com/asottile/setup-cfg-fmt
# rev: v1.20.1
# hooks:
# - id: setup-cfg-fmt

ci:
autoupdate_schedule: quarterly
2 changes: 1 addition & 1 deletion python/objToJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ PyObject* objToJSON(PyObject* self, PyObject *args, PyObject *kwargs)

if (encoder.allowNan)
{
csInf = "Inf";
csInf = "Infinity";
csNan = "NaN";
}

Expand Down
2 changes: 1 addition & 1 deletion python/ujson.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ PyObject* JSONDecodeError;
#define ENCODER_HELP_TEXT "Use ensure_ascii=false to output UTF-8. " \
"Set encode_html_chars=True to encode < > & as unicode escape sequences. "\
"Set escape_forward_slashes=False to prevent escaping / characters." \
"Set allow_nan=False to raise an exception when NaN or Inf would be serialized." \
"Set allow_nan=False to raise an exception when NaN or Infinity would be serialized." \
"Set reject_bytes=True to raise TypeError on bytes."

static PyMethodDef ujsonMethods[] = {
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/ultrajson/ultrajson
author = Jonas Tarnstrom
license_file = LICENSE.txt
license_files = LICENSE.txt
platforms = any
classifiers =
Development Status :: 5 - Production/Stable
Expand Down
4 changes: 2 additions & 2 deletions tests/test_ujson.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,8 @@ def test_encode_no_assert(test_input):
(1.0, "1.0"),
(OrderedDict([(1, 1), (0, 0), (8, 8), (2, 2)]), '{"1":1,"0":0,"8":8,"2":2}'),
({"a": float("NaN")}, '{"a":NaN}'),
({"a": float("inf")}, '{"a":Inf}'),
({"a": -float("inf")}, '{"a":-Inf}'),
({"a": float("inf")}, '{"a":Infinity}'),
({"a": -float("inf")}, '{"a":-Infinity}'),
],
)
def test_encode(test_input, expected):
Expand Down