flag: fix parse_bool_value() with different order short args (fix #22176) (#22242)

This commit is contained in:
yuyi 2024-09-18 01:07:23 +08:00 committed by GitHub
parent 97c9f5f9e4
commit 15bf8222b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View File

@ -304,7 +304,7 @@ fn (mut fs FlagParser) parse_bool_value(longhand string, shorthand u8) !string {
}
if arg.len > 1 && arg[0] == `-` && arg[1] != `-` {
mut found := false
for j in 1 .. arg.len - 1 {
for j in 1 .. arg.len {
if arg[j].is_space() {
break
} else if arg[j] == shorthand {

View File

@ -501,3 +501,16 @@ fn test_finalize_with_multi_shortargs() {
println(additional_args.join_lines())
assert additional_args == []
}
fn test_finalize_with_multi_shortargs_different_order() {
mut fp := flag.new_flag_parser(['-ba', '-c'])
a_bool := fp.bool('a_bool', `a`, false, '')
assert a_bool
b_bool := fp.bool('b_bool', `b`, false, '')
assert b_bool
c_bool := fp.bool('c_bool', `c`, false, '')
assert c_bool
additional_args := fp.finalize()!
println(additional_args.join_lines())
assert additional_args == []
}