Skip to content

Commit

Permalink
flag: fix parse_bool_value() with different order short args (fix #22176
Browse files Browse the repository at this point in the history
) (#22242)
  • Loading branch information
yuyi98 committed Sep 17, 2024
1 parent 97c9f5f commit 15bf822
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vlib/flag/flag.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions vlib/flag/flag_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 == []
}

0 comments on commit 15bf822

Please sign in to comment.