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

ruby-changes:47448

From: nobu <ko1@a...>
Date: Thu, 10 Aug 2017 14:55:05 +0900 (JST)
Subject: [ruby-changes:47448] nobu:r59564 (trunk): ruby.c: ignore non-option in shebang line

nobu	2017-08-10 14:54:56 +0900 (Thu, 10 Aug 2017)

  New Revision: 59564

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

  Log:
    ruby.c: ignore non-option in shebang line
    
    * ruby.c (moreswitches): process all words as options only in
      an environment variable, but not in a shebang line.
      [ruby-core:82267] [Bug #13786]

  Modified files:
    trunk/ruby.c
    trunk/test/ruby/test_rubyoptions.rb
Index: test/ruby/test_rubyoptions.rb
===================================================================
--- test/ruby/test_rubyoptions.rb	(revision 59563)
+++ test/ruby/test_rubyoptions.rb	(revision 59564)
@@ -338,6 +338,8 @@ class TestRubyOptions < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L338
                       %w[4], [], bug4118)
     assert_in_out_err(%w[-x], "#!/bin/sh\n""#!shebang\n""#!ruby\n""puts __LINE__\n",
                       %w[4], [], bug4118)
+
+    assert_ruby_status(%w[], "#! ruby -- /", '[ruby-core:82267] [Bug #13786]')
   end
 
   def test_sflag
Index: ruby.c
===================================================================
--- ruby.c	(revision 59563)
+++ ruby.c	(revision 59564)
@@ -731,11 +731,11 @@ moreswitches(const char *s, ruby_cmdline https://github.com/ruby/ruby/blob/trunk/ruby.c#L731
 
     while (ISSPACE(*s)) s++;
     if (!*s) return;
-    argstr = rb_str_tmp_new((len = strlen(s)) + 2);
+    argstr = rb_str_tmp_new((len = strlen(s)) + (envopt!=0));
     argary = rb_str_tmp_new(0);
 
     p = RSTRING_PTR(argstr);
-    *p++ = ' ';
+    if (envopt) *p++ = ' ';
     memcpy(p, s, len + 1);
     ap = 0;
     rb_str_cat(argary, (char *)&ap, sizeof(ap));
@@ -752,7 +752,7 @@ moreswitches(const char *s, ruby_cmdline https://github.com/ruby/ruby/blob/trunk/ruby.c#L752
     rb_str_cat(argary, (char *)&ap, sizeof(ap));
     argv = (char **)RSTRING_PTR(argary);
 
-    while ((i = proc_options(argc, argv, opt, envopt)) > 1 && (argc -= i) > 0) {
+    while ((i = proc_options(argc, argv, opt, envopt)) > 1 && envopt && (argc -= i) > 0) {
 	argv += i;
 	if (**argv != '-') {
 	    *--*argv = '-';

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

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