Skip to content

Commit

Permalink
fix(cli): prevent drive letters from being confused with namespaces i…
Browse files Browse the repository at this point in the history
…n 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.
  • Loading branch information
plusvic committed Jan 27, 2025
1 parent b4e8ad9 commit 43a264c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>, 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)))
Expand Down

0 comments on commit 43a264c

Please sign in to comment.