-
Notifications
You must be signed in to change notification settings - Fork 487
Properly handle non-unicode host locale #1505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
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
|
@@ -45,7 +45,7 @@ def fetch_build(repo_slug, build_number, token) | |||
url = "project/#{repo_slug}/#{build_number}" | |||
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
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.