Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 == []
}
Loading