Skip to content

Commit

Permalink
Forbid --output=file without a path separator
Browse files Browse the repository at this point in the history
  • Loading branch information
tavianator committed May 16, 2022
1 parent 419d5bd commit 600bbf2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ pub enum OptionsError<'a> {
EmptyShell,
#[error("Failed to parse '--shell <command>' expression as command line: {0}")]
ShellParseError(shell_words::ParseError),
#[error("Unknown output policy '{0}'. Use ./{0} to output to a file named {0}.")]
UnknownOutputPolicy(String),
}
8 changes: 7 additions & 1 deletion src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,13 @@ impl Options {
"null" => CommandOutputPolicy::Discard,
"pipe" => CommandOutputPolicy::Pipe,
"inherit" => CommandOutputPolicy::Forward,
path => CommandOutputPolicy::File(path.into()),
arg => {
let path = PathBuf::from(arg);
if path.components().count() <= 1 {
return Err(OptionsError::UnknownOutputPolicy(arg.to_string()))
}
CommandOutputPolicy::File(path)
}
}
} else {
CommandOutputPolicy::Discard
Expand Down

0 comments on commit 600bbf2

Please sign in to comment.