Accept nil for opts in pretty_generate
#767
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.
nilis a valid second argument toJSON.pretty_generate, in fact, it's the default.As a user of the
ojgem, I would expect that after invokingOj.mimic_JSON, this argument would still be valid.However, at least on the current version (I didn't check earlier versions), a mimicked
JSON.pretty_generatecrashes ruby with a segmentation fault insideoj_mimic_pretty_generate.This PR's first commit adds a test for this, which on my laptop ("ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-linux]") also crashes with a segfault.
The second commit adds a check to
oj_mimic_pretty_generateto handle anilsecond argument exactly as if there were no second argument. I think I did this right, at least the test passes now, but I haven't written C for a ruby extension before so of course I hope you'll correct me if there's a better way to do that.I haven't looked into other mimicked functions to see if there are similar issues.
I'd like to give credit to @antonivanopoulos in this blog post for uncovering this issue and doing a deep-dive explaining it thoroughly.
Thanks for your attention and for providing this open-source gem to the community!