Skip to content

Commit 8c8010e

Browse files
SteveL-MSFTCopilot
andcommitted
Update lib/dsc-lib/src/util.rs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 6cd4079 commit 8c8010e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/dsc-lib/src/util.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,12 @@ pub fn resource_id(type_name: &str, name: &str) -> String {
234234
}
235235

236236
pub fn canonicalize_which(executable: &str, cwd: Option<&str>) -> Result<String, DscError> {
237-
let mut executable = executable.to_string().replace("/", std::path::MAIN_SEPARATOR_STR);
238-
if cfg!(target_os = "windows") && !executable.ends_with(".exe") {
239-
let mut exe_path = PathBuf::from(&executable);
240-
exe_path.set_extension("exe");
241-
executable = exe_path.to_string_lossy().to_string();
237+
// Use PathBuf to handle path separators robustly
238+
let mut executable_path = PathBuf::from(executable);
239+
if cfg!(target_os = "windows") && executable_path.extension().map_or(true, |ext| ext != "exe") {
240+
executable_path.set_extension("exe");
242241
}
242+
let mut executable = executable_path.to_string_lossy().to_string();
243243
if which(&executable).is_err() && !Path::new(&executable).is_absolute() && cwd.is_some() {
244244
if let Some(cwd) = cwd {
245245
let cwd_path = Path::new(cwd);

0 commit comments

Comments
 (0)