ARGV: switch? should only has one dash
If user inputs argument such as `-with-flag`, we can assume it's a bad flag. Closes Homebrew/homebrew#49256 Closes Homebrew/homebrew#49550. Signed-off-by: Xu Cheng <xucheng@me.com>
This commit is contained in:
parent
ba147818cb
commit
73b79de7bc
@ -195,7 +195,7 @@ module HomebrewArgvExtension
|
|||||||
# eg. `foo -ns -i --bar` has three switches, n, s and i
|
# eg. `foo -ns -i --bar` has three switches, n, s and i
|
||||||
def switch?(char)
|
def switch?(char)
|
||||||
return false if char.length > 1
|
return false if char.length > 1
|
||||||
options_only.any? { |arg| arg[1, 1] != "-" && arg.include?(char) }
|
options_only.any? { |arg| arg.scan("-").size == 1 && arg.include?(char) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def usage
|
def usage
|
||||||
|
@ -48,9 +48,9 @@ class ArgvExtensionTests < Homebrew::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_switch?
|
def test_switch?
|
||||||
@argv << "-ns" << "-i" << "--bar"
|
@argv << "-ns" << "-i" << "--bar" << "-a-bad-arg"
|
||||||
%w[n s i].each { |s| assert @argv.switch?(s) }
|
%w[n s i].each { |s| assert @argv.switch?(s) }
|
||||||
%w[b ns bar --bar -n].each { |s| assert !@argv.switch?(s) }
|
%w[b ns bar --bar -n a bad arg].each { |s| assert !@argv.switch?(s) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_flag?
|
def test_flag?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user