diff options
-rw-r--r-- | ruby.c | 5 | ||||
-rw-r--r-- | test/ruby/test_rubyoptions.rb | 16 |
2 files changed, 21 insertions, 0 deletions
@@ -1737,6 +1737,11 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) VALUE path = Qnil; if (!opt->e_script && strcmp(opt->script, "-")) { path = rb_realpath_internal(Qnil, script_name, 1); +#if UTF8_PATH + if (uenc != lenc) { + path = str_conv_enc(path, uenc, lenc); + } +#endif } base_block = toplevel_context(toplevel_binding); iseq = rb_iseq_new_main(tree, opt->script_name, path, vm_block_iseq(base_block)); diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb index beb6a24e93..27969690d8 100644 --- a/test/ruby/test_rubyoptions.rb +++ b/test/ruby/test_rubyoptions.rb @@ -935,4 +935,20 @@ class TestRubyOptions < Test::Unit::TestCase end end end + + def test___dir__encoding + with_tmpchdir do + testdir = "\u30c6\u30b9\u30c8" + Dir.mkdir(testdir) + Dir.chdir(testdir) do + open("test.rb", "w") do |f| + f.puts <<-END + p __FILE__.encoding == __dir__.encoding + END + end + r, = EnvUtil.invoke_ruby("test.rb", "", true) + assert_equal "true", r.chomp, "the encoding of __FILE__ and __dir__ should be same" + end + end + end end |