From 291cc913503475a204c93a53a2f470c8cc6bfca2 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Fri, 28 Jun 2024 16:04:49 -0400 Subject: [Bug #20598] Fix corruption of internal encoding string (#11069) Fix corruption of internal encoding string [Bug #20598] Just like [Bug #20595], Encoding#name_list and Encoding#aliases can have their strings corrupted when Encoding.default_internal is set to nil. Co-authored-by: Matthew Valentine-House --- test/ruby/test_m17n.rb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'test/ruby') diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb index 58512f9041..e3fc36ef87 100644 --- a/test/ruby/test_m17n.rb +++ b/test/ruby/test_m17n.rb @@ -1722,14 +1722,20 @@ class TestM17N < Test::Unit::TestCase end def test_encoding_names_of_default_internal - # [Bug #20595] - assert_separately(%w(-W0), "#{<<~"begin;"}\n#{<<~"end;"}") - begin; - Encoding.default_internal = Encoding::ASCII_8BIT - names = Encoding.default_internal.names - Encoding.default_internal = nil - assert_include names, "int" + "ernal", "[Bug #20595]" - end; + # [Bug #20595] [Bug #20598] + [ + "default_internal.names", + "name_list", + "aliases.keys" + ].each do |method| + assert_separately(%w(-W0), <<~RUBY) + exp_name = "int" + "ernal" + Encoding.default_internal = Encoding::ASCII_8BIT + name = Encoding.#{method}.find { |x| x == exp_name } + Encoding.default_internal = nil + assert_equal exp_name, name, "Encoding.#{method} [Bug #20595] [Bug #20598]" + RUBY + end end def test_greek_capital_gap -- cgit v1.2.3