Make sure JSON output strings are sanitized #114
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Make sure we only output UTF-8 data in JSON generated from the FormatParser
results.
The reason we need to do it in this (rather elaborate) way is this:
JSON.generate
andfriends use a totally different code path than
"foo".to_json(generator_state)
. We cannot predictwhich one of these two ways our users will be using, and at the same time we need to prevent
invalid Strings (ones which cannot be encoded into UTF-8) as well as Float::INFINITY values
from being passed to the JSON encoder. Since we cannot override the JSON generator with
these additions, instead we will deep-convert the entire object being output to make sure
it is up to snuff.
All of the output of AttributesJSON will be sanitized this way.