Skip to content

Commit

Permalink
Fix crash when input has no match (#309)
Browse files Browse the repository at this point in the history
Fixes #307
  • Loading branch information
denisidoro authored Mar 24, 2020
1 parent ed0759f commit 4b5658a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn parse_opts(text: &str) -> Result<FzfOpts, Error> {
.context("Failed to parse fzf options")?;

let suggestion_type = match (multi, prevent_extra) {
(true, _) => SuggestionType::MultipleSelections, // multi wins over allow-extra
(true, _) => SuggestionType::MultipleSelections, // multi wins over prevent-extra
(false, false) => SuggestionType::SingleRecommendation,
(false, true) => SuggestionType::SingleSelection,
};
Expand Down Expand Up @@ -260,7 +260,8 @@ mod tests {
#[test]
fn test_parse_variable_line() {
let (variable, command, command_options) =
parse_variable_line("$ user : echo -e \"$(whoami)\\nroot\" --- --allow-extra").unwrap();
parse_variable_line("$ user : echo -e \"$(whoami)\\nroot\" --- --prevent-extra")
.unwrap();
assert_eq!(command, " echo -e \"$(whoami)\\nroot\" ");
assert_eq!(variable, "user");
assert_eq!(
Expand All @@ -269,7 +270,7 @@ mod tests {
header_lines: 0,
column: None,
delimiter: None,
suggestion_type: SuggestionType::SingleRecommendation,
suggestion_type: SuggestionType::SingleSelection,
..Default::default()
})
);
Expand All @@ -290,7 +291,7 @@ mod tests {
header_lines: 0,
column: None,
delimiter: None,
suggestion_type: SuggestionType::SingleRecommendation,
suggestion_type: SuggestionType::SingleSelection,
..Default::default()
}),
);
Expand Down
2 changes: 1 addition & 1 deletion src/structures/fzf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Default for Opts {
header_lines: 0,
header: None,
prompt: None,
suggestion_type: SuggestionType::SingleSelection,
suggestion_type: SuggestionType::SingleRecommendation,
column: None,
delimiter: None,
}
Expand Down
2 changes: 1 addition & 1 deletion tests/cheats/ssh.cheat
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# login to a server with a key and port
ssh -i <sshkey> -p <port> <user>@<server>

$ user : echo -e "$(whoami)\nroot" --- --allow-extra
$ user : echo -e "$(whoami)\nroot" --- --prevent-extra

0 comments on commit 4b5658a

Please sign in to comment.