flag: fix panic when given an empty string as args (#10937)
parent
29f55bdf9b
commit
304f26edeb
|
@ -212,7 +212,7 @@ fn (mut fs FlagParser) parse_value(longhand string, shorthand byte) []string {
|
|||
should_skip_one = false
|
||||
continue
|
||||
}
|
||||
if arg[0] != `-` {
|
||||
if arg.len == 0 || arg[0] != `-` {
|
||||
continue
|
||||
}
|
||||
if (arg.len == 2 && arg[0] == `-` && arg[1] == shorthand) || arg == full {
|
||||
|
|
|
@ -405,3 +405,8 @@ fn test_dashdash_acts_as_parser_full_stop_dashdash_at_end() ? {
|
|||
args := fp.finalize() ?
|
||||
assert args.len > 0
|
||||
}
|
||||
|
||||
fn test_empty_string_with_flag() {
|
||||
mut fp := flag.new_flag_parser([''])
|
||||
s := fp.string('something', `s`, 'default', 'Hey parse me')
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue