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

ruby-changes:50057

From: nobu <ko1@a...>
Date: Sat, 3 Feb 2018 12:50:32 +0900 (JST)
Subject: [ruby-changes:50057] nobu:r62175 (trunk): process.c: command_name encoding

nobu	2018-02-03 12:50:28 +0900 (Sat, 03 Feb 2018)

  New Revision: 62175

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

  Log:
    process.c: command_name encoding
    
    * process.c (rb_exec_fillarg): share subsequence of argv_buf for
      command_name, and copy the encoding from the command string.

  Modified files:
    trunk/process.c
    trunk/test/ruby/test_system.rb
Index: process.c
===================================================================
--- process.c	(revision 62174)
+++ process.c	(revision 62175)
@@ -2210,7 +2210,9 @@ rb_exec_fillarg(VALUE prog, int argc, VA https://github.com/ruby/ruby/blob/trunk/process.c#L2210
                 }
             }
             eargp->invoke.cmd.argv_buf = argv_buf;
-            eargp->invoke.cmd.command_name = hide_obj(rb_str_new_cstr(RSTRING_PTR(argv_buf)));
+            eargp->invoke.cmd.command_name =
+                hide_obj(rb_str_subseq(argv_buf, 0, strlen(RSTRING_PTR(argv_buf))));
+            rb_enc_copy(eargp->invoke.cmd.command_name, prog);
         }
     }
 #endif
Index: test/ruby/test_system.rb
===================================================================
--- test/ruby/test_system.rb	(revision 62174)
+++ test/ruby/test_system.rb	(revision 62175)
@@ -181,5 +181,21 @@ class TestSystem < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_system.rb#L181
     assert_raise_with_message(RuntimeError, /\ACommand failed with exit /) do
       system("'#{ruby}' -e abort", exception: true)
     end
+
+    Dir.mktmpdir("ruby_script_tmp") do |tmpdir|
+      name = "\u{30c6 30b9 30c8}"
+      tmpfilename = "#{tmpdir}/#{name}.cmd"
+      message = /#{name}\.cmd/
+      e = assert_raise_with_message(Errno::ENOENT, message) do
+        system(tmpfilename, exception: true)
+      end
+      open(tmpfilename, "w") {|f|
+        f.puts "exit 127"
+        f.chmod(0755)
+      }
+      e = assert_raise_with_message(RuntimeError, message) do
+        system(tmpfilename, exception: true)
+      end
+    end
   end
 end

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

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