Skip to content

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

ojab
Copy link

@ojab ojab commented Feb 6, 2025

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.

ojab added 5 commits February 6, 2025 11:29
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
@ojab ojab changed the title Use #to_h instead of Hash[Array#collect] Properly handle non-unicode host locale Feb 6, 2025
@ojab
Copy link
Author

ojab commented Feb 6, 2025

1 workflow awaiting approval, sending to review, bundle exec rspec/rubocop passes locally.

@ojab ojab marked this pull request as ready for review February 6, 2025 12:20
@manicmaniac manicmaniac self-requested a review February 9, 2025 17:38
@@ -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)
Copy link
Member

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy