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

ruby-changes:36571

From: nobu <ko1@a...>
Date: Sun, 30 Nov 2014 00:03:13 +0900 (JST)
Subject: [ruby-changes:36571] nobu:r48652 (trunk): ruby.c: transcode program names

nobu	2014-11-30 00:02:58 +0900 (Sun, 30 Nov 2014)

  New Revision: 48652

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

  Log:
    ruby.c: transcode program names
    
    * ruby.c (process_options, ruby_script): transcode script name and
      program name to locale encoding as well as argv.
      [ruby-dev:48752] [Bug #10555]

  Modified files:
    trunk/ChangeLog
    trunk/ruby.c
    trunk/test/ruby/test_rubyoptions.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48651)
+++ ChangeLog	(revision 48652)
@@ -1,4 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Sun Nov 30 00:02:22 2014  Nobuyoshi Nakada  <nobu@r...>
+Sun Nov 30 00:02:52 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* ruby.c (process_options, ruby_script): transcode script name and
+	  program name to locale encoding as well as argv.
+	  [ruby-dev:48752] [Bug #10555]
 
 	* ruby.c (translit_char_bin): should not use code page dependent
 	  CharNext on UTF-8 string.  [ruby-dev:48752] [Bug #10555]
Index: ruby.c
===================================================================
--- ruby.c	(revision 48651)
+++ ruby.c	(revision 48652)
@@ -346,6 +346,16 @@ translit_char_bin(char *p, int from, int https://github.com/ruby/ruby/blob/trunk/ruby.c#L346
 # define UTF8_PATH 0
 #endif
 
+#if UTF8_PATH
+static VALUE
+str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to)
+{
+    return rb_str_conv_enc_opts(str, from, to,
+				ECONV_UNDEF_REPLACE|ECONV_INVALID_REPLACE,
+				Qnil);
+}
+#endif
+
 void ruby_init_loadpath_safe(int safe_level);
 
 void
@@ -1404,6 +1414,10 @@ process_options(int argc, char **argv, s https://github.com/ruby/ruby/blob/trunk/ruby.c#L1414
 	rb_define_module("Gem");
     }
     ruby_init_prelude();
+#if UTF8_PATH
+    opt->script_name = str_conv_enc(opt->script_name, rb_utf8_encoding(), lenc);
+    opt->script = RSTRING_PTR(opt->script_name);
+#endif
     ruby_set_argv(argc, argv);
     process_sflag(&opt->sflag);
 
@@ -1819,9 +1833,7 @@ external_str_new_cstr(const char *p) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1833
 {
 #if UTF8_PATH
     VALUE str = rb_utf8_str_new_cstr(p);
-    return rb_str_conv_enc_opts(str, NULL, rb_default_external_encoding(),
-				ECONV_UNDEF_REPLACE|ECONV_INVALID_REPLACE,
-				Qnil);
+    return str_conv_enc(str, NULL, rb_default_external_encoding());
 #else
     return rb_external_str_new_cstr(p);
 #endif
@@ -1836,7 +1848,7 @@ void https://github.com/ruby/ruby/blob/trunk/ruby.c#L1848
 ruby_script(const char *name)
 {
     if (name) {
-	rb_orig_progname = rb_progname = rb_external_str_new(name, strlen(name));
+	rb_orig_progname = rb_progname = external_str_new_cstr(name);
 	rb_vm_set_progname(rb_progname);
     }
 }
Index: test/ruby/test_rubyoptions.rb
===================================================================
--- test/ruby/test_rubyoptions.rb	(revision 48651)
+++ test/ruby/test_rubyoptions.rb	(revision 48652)
@@ -705,6 +705,17 @@ class TestRubyOptions < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L705
                           bug10555, encoding: "locale")
       end
     end
+
+    def test_command_line_progname_nonascii
+      bug10555 = '[ruby-dev:48752] [Bug #10555]'
+      name = "\u{3042}.rb"
+      expected = name.encode("locale") rescue "?.rb"
+      with_tmpchdir do |dir|
+        open(name, "w") {|f| f.puts "puts File.basename($0)"}
+        assert_in_out_err([name], "", [expected], [],
+                          bug10555, encoding: "locale")
+      end
+    end
   end
 
   def test_script_is_directory

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

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