diff --git a/src/path.rs b/src/path.rs index be1bba5..f5017b0 100644 --- a/src/path.rs +++ b/src/path.rs @@ -356,6 +356,14 @@ pub fn convert_arg(arg: &str) -> Cow<'_, str> { if arg.len() < 2 { return Cow::Borrowed(arg); } + // `//x` is an escaped Windows switch (`cmd //c`, `taskkill //F`): as in MSYS, it loses one + // slash, unless it looks like a UNC path (`//server/share`). + if let Some(rest) = arg.strip_prefix("//") { + if rest.is_empty() || rest.starts_with('/') || !rest.contains('/') { + return Cow::Owned(arg[1..].to_string()); + } + return Cow::Borrowed(arg); + } let cwd = Path::new("C:\\"); if convertible(arg) { if arg == "/dev/null" { diff --git a/tests/scripts/067_double_slash_switches.code b/tests/scripts/067_double_slash_switches.code new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/tests/scripts/067_double_slash_switches.code @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/tests/scripts/067_double_slash_switches.out b/tests/scripts/067_double_slash_switches.out new file mode 100644 index 0000000..82cc441 --- /dev/null +++ b/tests/scripts/067_double_slash_switches.out @@ -0,0 +1,3 @@ + '/c' '/F' '//x' '//server/share/x' '//c/x' '/' +switch passed + '//c' diff --git a/tests/scripts/067_double_slash_switches.sh b/tests/scripts/067_double_slash_switches.sh new file mode 100644 index 0000000..7cd3f70 --- /dev/null +++ b/tests/scripts/067_double_slash_switches.sh @@ -0,0 +1,9 @@ +# An argument starting with // is an escaped Windows switch: a native program gets it with one +# slash fewer, as with MSYS (`cmd //c`, `taskkill //F`), unless it looks like `//server/share`. +# Start from no conversion settings, whatever the environment exports (Claude Code sets one). +unset MSYS_NO_PATHCONV MSYS2_ARG_CONV_EXCL +git rev-parse --sq-quote //c //F ///x //server/share/x //c/x // +cmd //c echo switch passed +export MSYS_NO_PATHCONV=1 +git rev-parse --sq-quote //c +unset MSYS_NO_PATHCONV