Repository navigation
Raise GeneratorError for colliding keys with rfc8785 and no as_json - #1155
Closed
Branson404 wants to merge 1 commit into
Closed
Branson404 wants to merge 1 commit into
Branson404 wants to merge 1 commit into
Conversation
In rfc8785 mode the duplicate key check re-coerced every key through as_json, which is nil for a non-strict generator and false for a strict Coder without a block, so a hash such as { "1" => 1, 1 => 2 } raised NoMethodError. Without an as_json converter the keys are stringified, as the sort proc already does, so do the same when looking for the duplicate. Fixes ruby#1152.
Member
|
Thanks for the patch, however I decided to go with a different fix: #1156 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #1152
With
rfc8785: true, a hash whose keys collide once stringified, such as{ "1" => 1, 1 => 2 }, raisedNoMethodError: undefined method 'call' for nil(orfor falsewith aJSON::Codercreated without a block) instead ofJSON::GeneratorError.on_duplicate_keyre-coerced every key throughas_json, but there is noas_jsonconverter in those configurations.Without a converter the keys are stringified, as the sort proc already does, so
on_duplicate_keynow does the same.Added a test for String/Integer and Symbol/Integer collisions and for a
JSON::Coderwithout a block; it fails without the change. Ran the fullrake test(703 tests, 0 failures) on Ruby 3.4 only; JRuby and other Ruby versions were not run.