Properly handle non-unicode host locale#1505
Open
ojab wants to merge 5 commits into
Open
Conversation
Simplifies code a bit and makes it shorter
`json` gem was made more strict wrt input string encoding [0] and if default locale is non-unicode (for example, default self-hosted GHA runner image in [1] does not have unicode locales) parsing could fail with `Encoding::InvalidByteSequenceError` [0] ruby/json#697 [1] https://github.com/actions/actions-runner-controller
`JSON.parse(fixture(path))` => `fixture_json(path)` and always parse JSON as UTF-8 string, so we're independent of the host locale
Author
|
|
manicmaniac
reviewed
Feb 9, 2025
| params = { "circle-token" => token } | ||
| response = client.get url, params, accept: "application/json" | ||
| JSON.parse(response.body, symbolize_names: true) | ||
| JSON.parse(response.body, symbolize_names: true, encoding: Encoding::UTF_8) |
Member
There was a problem hiding this comment.
I'm afraid that JSON.parse() does not have option encoding.
https://docs.ruby-lang.org/en/master/JSON.html#module-JSON-label-Parsing+Options
The workaround described in ruby/json adds encoding option to File.read().
ruby/json#697 (comment)
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.
See commit messages, should be pretty clear.
Was prompted to do it due to ruby/json#697 (see 351311c for details), found some other issues after enforcing ASCII locale in specs and possibly fixed #1492 as well along the way.