From 43a264c89efd4198c1fae14bd28ad7b16a143abf Mon Sep 17 00:00:00 2001 From: "Victor M. Alvarez" Date: Mon, 27 Jan 2025 13:34:05 +0100 Subject: [PATCH] fix(cli): prevent drive letters from being confused with namespaces in Windows. The CLI accepts arguments of the form `[NAMESPACE:]PATH`, with colons (`:`) separating the namespace from the path. In Windows a drive letter at the start of the path can be misinterpreted as a namespace. --- cli/src/commands/mod.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cli/src/commands/mod.rs b/cli/src/commands/mod.rs index 90dfb8cc..244e8dec 100644 --- a/cli/src/commands/mod.rs +++ b/cli/src/commands/mod.rs @@ -114,10 +114,19 @@ fn meta_file_value_parser( /// /// Returns the namespace and the path. If the namespace is not provided /// returns [`None`]. +/// +/// In Windows, namespaces with a single character are not allowed as they can +/// be confused with a drive letter. fn path_with_namespace_parser( input: &str, ) -> Result<(Option, PathBuf), anyhow::Error> { if let Some((namespace, path)) = input.split_once(':') { + // In Windows a namespace with a single letter could actually be a + // drive letter. + #[cfg(target_os = "windows")] + if namespace.len() == 1 { + return Ok((None, PathBuf::from(input))); + } Ok((Some(namespace.to_string()), PathBuf::from(path))) } else { Ok((None, PathBuf::from(input)))