mirror of
https://github.com/ruby/ruby.git
synced 2026-10-28 16:36:20 +08:00
[Bug #20958] Fix test_keys_encoding on hosts without en_US.UTF-8
`EnvUtil.invoke_ruby` forces the C locale on the child process, so the test set `LC_ALL=en_US.UTF-8` to get a UTF-8 locale back. That locale is not generated on the debian11 chkbuild host, where `setlocale` falls back to C and the ENV key comes out as ASCII-8BIT instead of the default internal encoding. Inherit the locale of the parent process instead, and omit the test when that locale is not UTF-8. https://rubyci.s3.amazonaws.com/debian11/ruby-master/log/20260725T093003Z.fail.html.gz
This commit is contained in:
1 parent
5f398e864a
commit
d29afc8ab8
1 file changed
+7
-5
Notes:
git
2026-07-26 02:45:08 +00:00
@@ -197,6 +197,7 @@ class TestEnv < Test::Unit::TestCase
|
||||
|
||||
def test_keys_encoding
|
||||
bug20958 = '[ruby-core:120277] [Bug #20958]'
|
||||
omit "locale encoding is not UTF-8" unless ENCODING == Encoding::UTF_8
|
||||
orig = ENV.to_hash
|
||||
ENV.clear
|
||||
key = "TEST20958\u{30c6 30b9 30c8}"
|
||||
@@ -206,14 +207,15 @@ class TestEnv < Test::Unit::TestCase
|
||||
omit "platform does not support UTF-8 environment variables."
|
||||
end
|
||||
EnvUtil.with_default_internal(nil) do
|
||||
enc = RUBY_PLATFORM =~ /mswin|mingw/ ?
|
||||
Encoding::UTF_8 : Encoding.find("locale")
|
||||
assert_equal(enc, ENV.keys.last.encoding, bug20958)
|
||||
assert_equal(key.encode(enc), ENV.keys.last, bug20958)
|
||||
assert_equal(ENCODING, ENV.keys.last.encoding, bug20958)
|
||||
assert_equal(key.encode(ENCODING), ENV.keys.last, bug20958)
|
||||
end
|
||||
|
||||
ENV.update(orig) #required to restore ENV[RbConfig::CONFIG['LIBPATHENV']]
|
||||
env = {key => "x", "LOCALE" => "en_US.UTF-8", "LC_ALL" => "en_US.UTF-8"}
|
||||
env = {key => "x"}
|
||||
# invoke_ruby forces the C locale, restore the locale of this process,
|
||||
# which is known to be UTF-8 here.
|
||||
EnvUtil::LANG_ENVS.each {|e| env[e] = ENV[e]}
|
||||
load_path = $LOAD_PATH.map {|v| "-I#{v}" }
|
||||
internal_enc = "Windows-31J"
|
||||
params = [env, *load_path, "-Eutf-8:#{internal_enc}"]
|
||||
|
||||
Reference in new issue
Block a user