Repository navigation
Raise on non-UTF-8 string keys in RFC 8785 mode - #1109
Open
Shaisolaris wants to merge 1 commit into
Open
Shaisolaris wants to merge 1 commit into
Shaisolaris wants to merge 1 commit into
Conversation
String hash keys that are not UTF-8 are invalid, so with rfc8785: true the generator now raises JSON::GeneratorError for them instead of transcoding them. A Latin-1 key used to be written the same as the UTF-8 key with the same characters, so the output could contain a duplicate key. Binary and invalid UTF-8 keys raised Encoding errors from the sort instead of GeneratorError. ASCII-only keys are still accepted in any ASCII-compatible encoding. Keys handed to as_json are converted as before. See ruby#1108.
This branch has not been deployed
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.
Follow-up to #1108. As suggested there, string keys that are not UTF-8 are treated as invalid in RFC 8785 mode, so the generator now raises instead of transcoding them.
On master:
With this change, all three raise
JSON::GeneratorError. The checks are inrfc8785_sort_keys_proc, on the path where noas_jsonconversion is used:"a".b, US-ASCII strings, and Symbols).{ "a".encode("UTF-16LE") => 1 }produced{"a":1}.as_json(withstrict: true) are converted as before.rfc8785: trueis affected. PlainJSON.generatekeeps its current behavior.Tests:
test_rfc8785_non_utf8_string_keys. It fails on master and passes with this change.test/json/*_test.rbfiles pass locally with the C extension on Ruby 3.3.8, with the same counts as master apart from the new test. I did not run the TruffleRuby or JRuby generators or the CI matrix.