summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-09-18 10:14:46 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-09-18 10:14:46 +0900
commitc87f2a4f156477ba962de19866a1f6298d567398 (patch)
treed01f20e6f3abb3250cf7de6d8c08c987d6dd0e52
parent5c6e00b090a81d233ccff98e0d642e7dd0182bd0 (diff)
[Bug #19887] RUBYOPT should work without leading `-`
-rw-r--r--ruby.c7
-rw-r--r--test/ruby/test_rubyoptions.rb3
2 files changed, 7 insertions, 3 deletions
diff --git a/ruby.c b/ruby.c
index be2ea2d0cd..0d70dbc84b 100644
--- a/ruby.c
+++ b/ruby.c
@@ -904,12 +904,13 @@ moreswitches(const char *s, ruby_cmdline_options_t *opt, int envopt)
opt->src.enc.name = opt->ext.enc.name = opt->intern.enc.name = 0;
- argstr = rb_str_tmp_new((len = strlen(s)) + (envopt!=0));
+ const int hyphen = *s != '-';
+ argstr = rb_str_tmp_new((len = strlen(s)) + hyphen);
argary = rb_str_tmp_new(0);
p = RSTRING_PTR(argstr);
- if (envopt) *p++ = ' ';
- memcpy(p, s, len + 1);
+ if (hyphen) *p = '-';
+ memcpy(p + hyphen, s, len + 1);
ap = 0;
rb_str_cat(argary, (char *)&ap, sizeof(ap));
while (*p) {
diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb
index d174bda50f..ccba49ea99 100644
--- a/test/ruby/test_rubyoptions.rb
+++ b/test/ruby/test_rubyoptions.rb
@@ -416,6 +416,9 @@ class TestRubyOptions < Test::Unit::TestCase
assert_in_out_err(%w(), "p Warning[:experimental]", ["false"])
ENV['RUBYOPT'] = '-W:qux'
assert_in_out_err(%w(), "", [], /unknown warning category: `qux'/)
+
+ ENV['RUBYOPT'] = 'w'
+ assert_in_out_err(%w(), "p $VERBOSE", ["true"])
ensure
ENV['RUBYOPT'] = rubyopt_orig
end