flag: fix panic when given an empty string as args (#10937)

pull/10935/head
a-iga 2021-07-24 17:26:00 +09:00 committed by GitHub
parent 29f55bdf9b
commit 304f26edeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -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 {

View File

@ -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')
}