From efdf7357238fb510137783e7c7680807b3c5247f Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Mon, 16 May 2022 16:23:12 -0400 Subject: [PATCH] Forbid --output=file without a path separator --- src/error.rs | 2 ++ src/options.rs | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/error.rs b/src/error.rs index 19bec56..72701c4 100644 --- a/src/error.rs +++ b/src/error.rs @@ -49,4 +49,6 @@ pub enum OptionsError<'a> { EmptyShell, #[error("Failed to parse '--shell ' 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), } diff --git a/src/options.rs b/src/options.rs index cf57472..aed0156 100644 --- a/src/options.rs +++ b/src/options.rs @@ -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