ruby-changes:70813
From: Nobuyoshi <ko1@a...>
Date: Tue, 11 Jan 2022 11:53:36 +0900 (JST)
Subject: [ruby-changes:70813] 1c9b5d452e (master): Reject command line option ending with `-`
https://git.ruby-lang.org/ruby.git/commit/?id=1c9b5d452e From 1c9b5d452e9f2f675130f13393a031e28bf982d7 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Tue, 11 Jan 2022 11:45:24 +0900 Subject: Reject command line option ending with `-` --- ruby.c | 3 ++- test/ruby/test_rubyoptions.rb | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ruby.c b/ruby.c index b98f1252753..e26996ec90c 100644 --- a/ruby.c +++ b/ruby.c @@ -1460,7 +1460,8 @@ proc_options(long argc, char **argv, ruby_cmdline_options_t *opt, int envopt) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1460 # define is_option_with_arg(name, allow_hyphen, allow_envopt) \ is_option_with_optarg(name, allow_hyphen, allow_envopt, Qtrue, Qtrue) # define is_option_with_optarg(name, allow_hyphen, allow_envopt, needs_arg, next_arg) \ - (strncmp((name), s, n = sizeof(name) - 1) == 0 && is_option_end(s[n], (allow_hyphen)) ? \ + (strncmp((name), s, n = sizeof(name) - 1) == 0 && is_option_end(s[n], (allow_hyphen)) && \ + (s[n] != '-' || s[n+1]) ? \ (check_envopt(name, (allow_envopt)), s += n, \ need_argument(name, s, needs_arg, next_arg), 1) : 0) diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb index c3dbef1b5e8..2cbd902f1fb 100644 --- a/test/ruby/test_rubyoptions.rb +++ b/test/ruby/test_rubyoptions.rb @@ -121,6 +121,8 @@ class TestRubyOptions < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L121 assert_in_out_err(["--disable-gems", "--debug", "-e", "p $DEBUG"], "", %w(true), []) + + assert_in_out_err(["--disable-gems", "--debug-", "-e", "p $DEBUG"], "", %w(), /invalid option --debug-/) end q = Regexp.method(:quote) -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/