Skip to content

Properly handle non-unicode host locale#1505

Open
ojab wants to merge 5 commits into
danger:masterfrom
ojab:fixup_non_unicode_locale_issues
Open

Properly handle non-unicode host locale#1505
ojab wants to merge 5 commits into
danger:masterfrom
ojab:fixup_non_unicode_locale_issues

Conversation

@ojab

@ojab ojab commented Feb 6, 2025

Copy link
Copy Markdown

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

ojab commented Feb 6, 2025

Copy link
Copy Markdown
Author

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
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
Copy Markdown
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