Skip to content

Commit

Permalink
fix(parser): Value terminator has higher precedence than later multip…
Browse files Browse the repository at this point in the history
…le values

This is one of several bugs found when looking at #4960.
  • Loading branch information
epage committed Jul 21, 2023
1 parent bdf205b commit 8bee728
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
9 changes: 8 additions & 1 deletion clap_builder/src/parser/parser.rs
Expand Up @@ -302,14 +302,21 @@ impl<'cmd> Parser<'cmd> {
.map(|p_name| !p_name.is_last_set())
.unwrap_or_default();

let is_terminated = self
.cmd
.get_keymap()
.get(&pos_counter)
.map(|a| a.get_value_terminator().is_some())
.unwrap_or_default();

let missing_pos = self.cmd.is_allow_missing_positional_set()
&& is_second_to_last
&& !trailing_values;

debug!("Parser::get_matches_with: Positional counter...{pos_counter}");
debug!("Parser::get_matches_with: Low index multiples...{low_index_mults:?}");

if low_index_mults || missing_pos {
if (low_index_mults || missing_pos) && !is_terminated {
let skip_current = if let Some(n) = raw_args.peek(&args_cursor) {
if let Some(arg) = self
.cmd
Expand Down
9 changes: 1 addition & 8 deletions tests/builder/multiple_values.rs
Expand Up @@ -1391,21 +1391,14 @@ fn all_multiple_value_terminator() {
let m = m.unwrap();

assert!(m.contains_id("files"));
assert!(m.contains_id("other"));
assert!(!m.contains_id("other"));
assert_eq!(
m.get_many::<String>("files")
.unwrap()
.map(|v| v.as_str())
.collect::<Vec<_>>(),
["value".to_owned()],
);
assert_eq!(
m.get_many::<String>("other")
.unwrap()
.map(|v| v.as_str())
.collect::<Vec<_>>(),
[";".to_owned()],
);
}

#[test]
Expand Down

0 comments on commit 8bee728

Please sign in to comment.