From 85f7bb62770e7f6c80402c2528c520e2717a2b24 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Fri, 12 Sep 2025 19:22:24 +0200 Subject: [PATCH] extension_host: Replace backslashes with forward slashes for cwd on Windows (#38072) Instead of passing CWD verbatim from the Windows host with backslashes and all, we now rewrite it into a more POSIX-happy format featuring forward slashes which means `std::path::Path` operations now work within WASI with Windows-style paths. Release Notes: - N/A --- crates/extension_host/src/wasm_host.rs | 8 +++++--- extensions/test-extension/src/test_extension.rs | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/extension_host/src/wasm_host.rs b/crates/extension_host/src/wasm_host.rs index 3ff8fcf7a408a78decca2b36eff9ade89f0a4072..a14bb860dbf19b3a42a989a33fa7fd6ea84d26a5 100644 --- a/crates/extension_host/src/wasm_host.rs +++ b/crates/extension_host/src/wasm_host.rs @@ -666,15 +666,17 @@ impl WasmHost { let file_perms = wasi::FilePerms::all(); let dir_perms = wasi::DirPerms::all(); - let path = SanitizedPath::new(&extension_work_dir); + let path = SanitizedPath::new(&extension_work_dir).to_string(); + #[cfg(target_os = "windows")] + let path = path.replace('\\', "/"); let mut ctx = wasi::WasiCtxBuilder::new(); ctx.inherit_stdio() - .env("PWD", path.to_string()) + .env("PWD", &path) .env("RUST_BACKTRACE", "full"); ctx.preopened_dir(&path, ".", dir_perms, file_perms)?; - ctx.preopened_dir(&path, path.to_string(), dir_perms, file_perms)?; + ctx.preopened_dir(&path, &path, dir_perms, file_perms)?; Ok(ctx.build()) } diff --git a/extensions/test-extension/src/test_extension.rs b/extensions/test-extension/src/test_extension.rs index 8c7737ba7faaaa64204cb04c81c16c42d8d46f37..0b96f470386fcc08a62b487cc36a448c4514854b 100644 --- a/extensions/test-extension/src/test_extension.rs +++ b/extensions/test-extension/src/test_extension.rs @@ -18,6 +18,10 @@ impl TestExtension { let current_dir = std::env::current_dir().unwrap(); println!("current_dir: {}", current_dir.display()); + assert_eq!( + current_dir.file_name().unwrap().to_str().unwrap(), + "test-extension" + ); fs::create_dir_all(current_dir.join("dir-created-with-abs-path")).unwrap(); fs::create_dir_all("./dir-created-with-rel-path").unwrap();