getoptlong.rb: multiline regexps
* lib/getoptlong.rb: make regexps multiline safe. [ruby-core:82627] [Bug #13858] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59722 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0465916576
commit
0f6e7edf72
@ -310,7 +310,7 @@ class GetoptLong
|
|||||||
#
|
#
|
||||||
next if i == argument_flag
|
next if i == argument_flag
|
||||||
begin
|
begin
|
||||||
if !i.is_a?(String) || i !~ /^-([^-]|-.+)$/
|
if !i.is_a?(String) || i !~ /\A-([^-]|-.+)\z/
|
||||||
raise ArgumentError, "an invalid option `#{i}'"
|
raise ArgumentError, "an invalid option `#{i}'"
|
||||||
end
|
end
|
||||||
if (@canonical_names.include?(i))
|
if (@canonical_names.include?(i))
|
||||||
@ -447,7 +447,7 @@ class GetoptLong
|
|||||||
terminate
|
terminate
|
||||||
return nil
|
return nil
|
||||||
elsif @ordering == PERMUTE
|
elsif @ordering == PERMUTE
|
||||||
while 0 < ARGV.length && ARGV[0] !~ /^-./
|
while 0 < ARGV.length && ARGV[0] !~ /\A-./
|
||||||
@non_option_arguments.push(ARGV.shift)
|
@non_option_arguments.push(ARGV.shift)
|
||||||
end
|
end
|
||||||
if ARGV.length == 0
|
if ARGV.length == 0
|
||||||
@ -456,7 +456,7 @@ class GetoptLong
|
|||||||
end
|
end
|
||||||
argument = ARGV.shift
|
argument = ARGV.shift
|
||||||
elsif @ordering == REQUIRE_ORDER
|
elsif @ordering == REQUIRE_ORDER
|
||||||
if (ARGV[0] !~ /^-./)
|
if (ARGV[0] !~ /\A-./)
|
||||||
terminate
|
terminate
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
@ -477,7 +477,7 @@ class GetoptLong
|
|||||||
#
|
#
|
||||||
# Check for long and short options.
|
# Check for long and short options.
|
||||||
#
|
#
|
||||||
if argument =~ /^(--[^=]+)/ && @rest_singles.length == 0
|
if argument =~ /\A(--[^=]+)/ && @rest_singles.length == 0
|
||||||
#
|
#
|
||||||
# This is a long style option, which start with `--'.
|
# This is a long style option, which start with `--'.
|
||||||
#
|
#
|
||||||
@ -507,7 +507,7 @@ class GetoptLong
|
|||||||
# Check an argument to the option.
|
# Check an argument to the option.
|
||||||
#
|
#
|
||||||
if @argument_flags[option_name] == REQUIRED_ARGUMENT
|
if @argument_flags[option_name] == REQUIRED_ARGUMENT
|
||||||
if argument =~ /=(.*)$/
|
if argument =~ /=(.*)/m
|
||||||
option_argument = $1
|
option_argument = $1
|
||||||
elsif 0 < ARGV.length
|
elsif 0 < ARGV.length
|
||||||
option_argument = ARGV.shift
|
option_argument = ARGV.shift
|
||||||
@ -516,19 +516,19 @@ class GetoptLong
|
|||||||
"option `#{argument}' requires an argument")
|
"option `#{argument}' requires an argument")
|
||||||
end
|
end
|
||||||
elsif @argument_flags[option_name] == OPTIONAL_ARGUMENT
|
elsif @argument_flags[option_name] == OPTIONAL_ARGUMENT
|
||||||
if argument =~ /=(.*)$/
|
if argument =~ /=(.*)/m
|
||||||
option_argument = $1
|
option_argument = $1
|
||||||
elsif 0 < ARGV.length && ARGV[0] !~ /^-./
|
elsif 0 < ARGV.length && ARGV[0] !~ /\A-./
|
||||||
option_argument = ARGV.shift
|
option_argument = ARGV.shift
|
||||||
else
|
else
|
||||||
option_argument = ''
|
option_argument = ''
|
||||||
end
|
end
|
||||||
elsif argument =~ /=(.*)$/
|
elsif argument =~ /=(.*)/m
|
||||||
set_error(NeedlessArgument,
|
set_error(NeedlessArgument,
|
||||||
"option `#{option_name}' doesn't allow an argument")
|
"option `#{option_name}' doesn't allow an argument")
|
||||||
end
|
end
|
||||||
|
|
||||||
elsif argument =~ /^(-(.))(.*)/
|
elsif argument =~ /\A(-(.))(.*)/m
|
||||||
#
|
#
|
||||||
# This is a short style option, which start with `-' (not `--').
|
# This is a short style option, which start with `-' (not `--').
|
||||||
# Short options may be catenated (e.g. `-l -g' is equivalent to
|
# Short options may be catenated (e.g. `-l -g' is equivalent to
|
||||||
@ -555,7 +555,7 @@ class GetoptLong
|
|||||||
if 0 < @rest_singles.length
|
if 0 < @rest_singles.length
|
||||||
option_argument = @rest_singles
|
option_argument = @rest_singles
|
||||||
@rest_singles = ''
|
@rest_singles = ''
|
||||||
elsif 0 < ARGV.length && ARGV[0] !~ /^-./
|
elsif 0 < ARGV.length && ARGV[0] !~ /\A-./
|
||||||
option_argument = ARGV.shift
|
option_argument = ARGV.shift
|
||||||
else
|
else
|
||||||
option_argument = ''
|
option_argument = ''
|
||||||
|
@ -52,4 +52,10 @@ describe :getoptlong_get, shared: true do
|
|||||||
lambda { @opts.send(@method) }.should raise_error(GetoptLong::MissingArgument)
|
lambda { @opts.send(@method) }.should raise_error(GetoptLong::MissingArgument)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns multiline argument" do
|
||||||
|
argv [ "--size=\n10k\n" ] do
|
||||||
|
@opts.send(@method).should == [ "--size", "\n10k\n" ]
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user