Skip to content

Commit f52dd84

Browse files
authored
fix(fs): use forward-slash paths in normalize_path on all platforms (#642)
## Summary - Fix `normalize_path` to build paths using forward slashes on all platforms - The VFS is always Unix-style, but `PathBuf` uses native separators (backslash on Windows) - This caused `pwd` to return `/tmp\navtest` instead of `/tmp/navtest` on Windows ## Test plan - [x] All Rust tests pass - [ ] CI green - [ ] Windows JS tests should pass after this fix
1 parent 21a9b56 commit f52dd84

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

crates/bashkit/src/fs/mod.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -420,21 +420,30 @@ use std::path::{Path, PathBuf};
420420
/// `/../..`), returns `/`.
421421
pub fn normalize_path(path: &Path) -> PathBuf {
422422
use std::path::Component;
423-
let mut result = PathBuf::new();
423+
// Build path as String with forward slashes to ensure Unix-style paths
424+
// on all platforms (the VFS is always Unix-style, even on Windows).
425+
let mut segments: Vec<&str> = Vec::new();
424426
for component in path.components() {
425427
match component {
426-
Component::RootDir => result.push("/"),
427-
Component::Normal(name) => result.push(name),
428+
Component::RootDir => {
429+
segments.clear();
430+
}
431+
Component::Normal(name) => {
432+
if let Some(s) = name.to_str() {
433+
segments.push(s);
434+
}
435+
}
428436
Component::ParentDir => {
429-
result.pop();
437+
segments.pop();
430438
}
431439
Component::CurDir | Component::Prefix(_) => {}
432440
}
433441
}
434-
if result.as_os_str().is_empty() {
435-
result.push("/");
442+
if segments.is_empty() {
443+
PathBuf::from("/")
444+
} else {
445+
PathBuf::from(format!("/{}", segments.join("/")))
436446
}
437-
result
438447
}
439448

440449
/// Verify that a filesystem implementation meets minimum requirements for Bashkit.

0 commit comments

Comments
 (0)