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

Adding safer JSON parsing for NaN Infinity and null #134

Merged
merged 2 commits into from
Jul 17, 2023

Conversation

LeStarch
Copy link
Collaborator

Originating Project/Creator
Affected Component
Affected Architectures(s)
Related Issue(s)
Has Unit Tests (y/n)
Builds Without Errors (y/n)
Unit Tests Pass (y/n)
Documentation Included (y/n)

Change Description

Fixes a bug where Python's JSON supports NaN and Infinity values, but JavaScript does not. This fix replaces those references with a string representation and then replaces them back in post.

@LeStarch LeStarch requested a review from jwest115 July 14, 2023 00:09
Comment on lines +70 to +76
this.FLAG = "-_-您好"; // Extended character usage make collisions less-likely
this.MAPPINGS = [
["-Infinity", this.FLAG + "-inf", -Infinity],
["Infinity", this.FLAG + "inf", Infinity],
["NaN", this.FLAG + "nan", NaN],
["null", this.FLAG + "null", null]
];
Copy link
Collaborator

Choose a reason for hiding this comment

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

@LeStarch why are we using a flag here? Is it so that if "-inf", "inf", "nan", or "null" appear in a string we could differentiate between that and the substring converted by the SafeParser?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes. A better flag-free solution would have required changes on both the Python end and here. It seemed a localized solution converting to something safe and immediately back was a better solution because:

  1. Colocated changes
  2. Does not increase size of transmitted data
  3. These cases should be sufficiently rare as to not merit a much more complex and comprehensive solution

Copy link
Collaborator

Choose a reason for hiding this comment

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

thanks for the explanation! looks good to me!

@LeStarch LeStarch merged commit 928a264 into nasa:devel Jul 17, 2023
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants