aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ruby.c3
-rw-r--r--test/ruby/test_rubyoptions.rb9
2 files changed, 10 insertions, 2 deletions
diff --git a/ruby.c b/ruby.c
index f0af34a9a8..452d0a0e3c 100644
--- a/ruby.c
+++ b/ruby.c
@@ -1744,6 +1744,9 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
path = str_conv_enc(path, uenc, lenc);
}
#endif
+ if (!ENCODING_GET(path)) { /* ASCII-8BIT */
+ rb_enc_copy(path, opt->script_name);
+ }
}
base_block = toplevel_context(toplevel_binding);
iseq = rb_iseq_new_main(ast->root, opt->script_name, path, vm_block_iseq(base_block));
diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb
index c3ec35d345..083dcec027 100644
--- a/test/ruby/test_rubyoptions.rb
+++ b/test/ruby/test_rubyoptions.rb
@@ -952,16 +952,21 @@ class TestRubyOptions < Test::Unit::TestCase
end
def test___dir__encoding
+ lang = {"LC_ALL"=>ENV["LC_ALL"]||ENV["LANG"]}
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
+ if __FILE__.encoding == __dir__.encoding
+ p true
+ else
+ puts "__FILE__: \#{__FILE__.encoding}, __dir__: \#{__dir__.encoding}"
+ end
END
end
- r, = EnvUtil.invoke_ruby("test.rb", "", true)
+ r, = EnvUtil.invoke_ruby([lang, "test.rb"], "", true)
assert_equal "true", r.chomp, "the encoding of __FILE__ and __dir__ should be same"
end
end