Skip to content

Commit 2dc500c

Browse files
authored
Merge pull request #6198 from devjgm/greg/fix-clap-completer-issue-with-fish
fix: Path quoting with dynamic env completer
2 parents ac1006c + 2280d48 commit 2dc500c

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

clap_complete/src/env/shells.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl EnvCompleter for Fish {
224224

225225
writeln!(
226226
buf,
227-
r#"complete --keep-order --exclusive --command {bin} --arguments "({var}=fish "'{completer}'" -- (commandline --current-process --tokenize --cut-at-cursor) (commandline --current-token))""#
227+
r#"complete --keep-order --exclusive --command {bin} --arguments "({var}=fish {completer} -- (commandline --current-process --tokenize --cut-at-cursor) (commandline --current-token))""#
228228
)
229229
}
230230
fn write_complete(
@@ -476,25 +476,19 @@ mod tests {
476476
let script = get_fish_registration("completer");
477477
assert_data_eq!(
478478
script.trim(),
479-
snapbox::str![r#"complete [..] "([..] "'completer'"[..])""#]
479+
snapbox::str![r#"complete [..] "([..] completer [..])""#]
480480
);
481481

482482
let script = get_fish_registration("/path/completer");
483483
assert_data_eq!(
484484
script.trim(),
485-
snapbox::str![r#"complete [..] "([..] "'/path/completer'"[..])""#]
485+
snapbox::str![r#"complete [..] "([..] /path/completer [..])""#]
486486
);
487487

488-
// This case demonstrates the existing bug when handling paths with spaces as described in
489-
// https://github.com/clap-rs/clap/issues/6196
490-
// The problem shown here is:
491-
// * The double quote started at `"(` is closed by the double quote before the path
492-
// * Then we have an empty pair of single quotes
493-
// * Then we have the _unquoted_ path with a space, which is problematic
494488
let script = get_fish_registration("/path with a space/completer");
495489
assert_data_eq!(
496490
script.trim(),
497-
snapbox::str![r#"complete [..] "([..] "''/path with a space/completer''"[..])""#]
491+
snapbox::str![r#"complete [..] "([..] '/path with a space/completer' [..])""#]
498492
);
499493
}
500494
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
complete --keep-order --exclusive --command exhaustive --arguments "(COMPLETE=fish "'exhaustive'" -- (commandline --current-process --tokenize --cut-at-cursor) (commandline --current-token))"
1+
complete --keep-order --exclusive --command exhaustive --arguments "(COMPLETE=fish exhaustive -- (commandline --current-process --tokenize --cut-at-cursor) (commandline --current-token))"

0 commit comments

Comments
 (0)