From: merch-redmine@... Date: 2020-11-18T20:45:29+00:00 Subject: [ruby-core:100939] [Ruby master Bug#17308] RubyVM::InstructionSequence.compile_file doesn't use the same default encoding than Kernel.load Issue #17308 has been updated by jeremyevans0 (Jeremy Evans). I submitted a pull request to make RubyVM::InstructionSequence.compile_file use same encoding as Kernel#load: https://github.com/ruby/ruby/pull/3788 ---------------------------------------- Bug #17308: RubyVM::InstructionSequence.compile_file doesn't use the same default encoding than Kernel.load https://bugs.ruby-lang.org/issues/17308#change-88593 * Author: byroot (Jean Boussier) * Status: Open * Priority: Normal * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- ```ruby def test_compile_file_encoding Tempfile.create(%w"test_iseq .rb") do |f| f.puts '{ "�" => "Th", "�" => "ss", "�" => "a" }' f.close previous_external = Encoding.default_external Encoding.default_external = Encoding::US_ASCII begin load f.path RubyVM::InstructionSequence.compile_file(f.path) ensure Encoding.default_external = previous_external end end end ``` In the above test case, `load` assumes that the source file is `UTF-8` whereas `compile_file` uses `default_external` causing various problems: ``` [1/1] TestISeq#test_compile_file_encoding test_iseq20201106-96756-2c0cz.rb:1: warning: key "" is duplicated and overwritten on line 1 test_iseq20201106-96756-2c0cz.rb:1: warning: key "" is duplicated and overwritten on line 1 = 0.00 s 1) Error: TestISeq#test_compile_file_encoding: SyntaxError: test_iseq20201106-96756-2c0cz.rb:1: invalid multibyte char (US-ASCII) test_iseq20201106-96756-2c0cz.rb:1: invalid multibyte char (US-ASCII) test_iseq20201106-96756-2c0cz.rb:1: invalid multibyte char (US-ASCII) test_iseq20201106-96756-2c0cz.rb:1: invalid multibyte char (US-ASCII) test_iseq20201106-96756-2c0cz.rb:1: invalid multibyte char (US-ASCII) test_iseq20201106-96756-2c0cz.rb:1: invalid multibyte char (US-ASCII) ruby/test/ruby/test_iseq.rb:283:in `compile_file' ruby/test/ruby/test_iseq.rb:283:in `block in test_compile_file_encoding' ruby/lib/tempfile.rb:358:in `create' ruby/test/ruby/test_iseq.rb:275:in `test_compile_file_encoding' ``` I believe `compile_file` should be consistent with `load`, or at least properly default to `UTF-8` like load does. -- https://bugs.ruby-lang.org/ Unsubscribe: