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

New Rule: unsafe values #29

Open
1 task done
bmeck opened this issue Oct 3, 2024 · 1 comment · May be fixed by #30
Open
1 task done

New Rule: unsafe values #29

bmeck opened this issue Oct 3, 2024 · 1 comment · May be fixed by #30

Comments

@bmeck
Copy link

bmeck commented Oct 3, 2024

Rule details

Fail on values that aren't safe for interchange

What type of rule is this?

Warns about a potential problem

Example code

Per https://socket.dev/blog/judicious-json

Some values of JSON do not coerce safely across different situations.

  1. Non-finite numbers. The can coerce to infinity or other precision loss.
// 'null'
JSON.stringify(Number.MAX_VALUE * 10)
// Infinity
JSON.parse('2e309')
  1. Lone surrogates. These actually throw errors in various libs.
let serialized = JSON.stringify("🔥"[0]);
// '"\\uD83D"' - note extra \
JSON.parse(serialized);
// "\uD83D"
  1. Array/string bounds. These have hard limits in some languages like JS.

This isn't feasible to show an example of. Only affects very large data. Uncommon and easily skipped usually.

Participation

  • I am willing to submit a pull request to implement this rule.

Additional comments

No response

@bmeck bmeck added the feature label Oct 3, 2024
@nzakas nzakas added the accepted label Oct 3, 2024
@nzakas
Copy link
Member

nzakas commented Oct 3, 2024

This sounds like a great idea for a no-unsafe-values rule. 👍 Feel free to submit a PR.

bmeck added a commit to bmeck/eslint-json that referenced this issue Oct 3, 2024
@bmeck bmeck linked a pull request Oct 3, 2024 that will close this issue
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants