diff --git a/crates/clash-verge-runtime-bundle/src/lib.rs b/crates/clash-verge-runtime-bundle/src/lib.rs index 728de705f..16aee2f8d 100644 --- a/crates/clash-verge-runtime-bundle/src/lib.rs +++ b/crates/clash-verge-runtime-bundle/src/lib.rs @@ -445,7 +445,7 @@ fn destination_below_root(config_root: &Path, path: &Path) -> Result { } fn normalized_destination(relative: &Path) -> Result { - let mut destination = PathBuf::new(); + let mut destination = PathBuf::with_capacity(relative.as_os_str().len()); for component in relative.components() { match component { Component::Normal(component) => destination.push(component), @@ -456,7 +456,15 @@ fn normalized_destination(relative: &Path) -> Result { if destination.as_os_str().is_empty() { return Err(RuntimeBundleError::EmptyDestination); } - Ok(destination.to_string_lossy().replace('\\', "/")) + let destination = destination + .into_os_string() + .into_string() + .unwrap_or_else(|path| path.to_string_lossy().into_owned()); + if destination.contains('\\') { + Ok(destination.replace('\\', "/")) + } else { + Ok(destination) + } } #[cfg(test)]