[前][次][番号順一覧][スレッド一覧]

ruby-changes:48186

From: usa <ko1@a...>
Date: Sun, 22 Oct 2017 00:43:08 +0900 (JST)
Subject: [ruby-changes:48186] usa:r60300 (trunk): The encoding of __FILE__ and __dir__ should be same

usa	2017-10-22 00:43:05 +0900 (Sun, 22 Oct 2017)

  New Revision: 60300

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60300

  Log:
    The encoding of __FILE__ and __dir__ should be same
    
    * ruby.c (process_options): convert the real path of the script to locale
      encoding if its encoding is not locale (maybe UTF-8) on Windows/OS X.
      this change makes the encoding of __dir__ to the same encoding of __FILE__
      when the script name is passed from commandline.
    
    * test/ruby/test_options.rb (test___dir__encoding): test for this change.

  Modified files:
    trunk/ruby.c
    trunk/test/ruby/test_rubyoptions.rb
Index: test/ruby/test_rubyoptions.rb
===================================================================
--- test/ruby/test_rubyoptions.rb	(revision 60299)
+++ test/ruby/test_rubyoptions.rb	(revision 60300)
@@ -935,4 +935,20 @@ class TestRubyOptions < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L935
       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
Index: ruby.c
===================================================================
--- ruby.c	(revision 60299)
+++ ruby.c	(revision 60300)
@@ -1737,6 +1737,11 @@ process_options(int argc, char **argv, r https://github.com/ruby/ruby/blob/trunk/ruby.c#L1737
 	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));

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]