From 2e57f1fca7cc62cb34d9f945c7990d359adb04a9 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 13 May 2022 12:07:30 -0500 Subject: [PATCH] fix(parser): Disallow empty paths --- src/builder/value_parser.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/builder/value_parser.rs b/src/builder/value_parser.rs index 94293a6e..fc2c1754 100644 --- a/src/builder/value_parser.rs +++ b/src/builder/value_parser.rs @@ -342,10 +342,19 @@ impl TypedValueParser for PathBufValueParser { fn parse( &self, - _cmd: &crate::Command, - _arg: Option<&crate::Arg>, + cmd: &crate::Command, + arg: Option<&crate::Arg>, value: std::ffi::OsString, ) -> Result { + if value.is_empty() { + return Err(crate::Error::empty_value( + cmd, + &[], + arg.map(ToString::to_string) + .unwrap_or_else(|| "...".to_owned()), + crate::output::Usage::new(cmd).create_usage_with_title(&[]), + )); + } Ok(Self::Value::from(value)) } }