From 880a5eaad9dcdfd31563385f11ba1f63d38cfd14 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 9 Aug 2026 06:19:30 +0900 Subject: refactor(php-shim): use std::path::MAIN_SEPARATOR over a shim constant The shim's DIRECTORY_SEPARATOR was hardcoded to "/", so every ported `'\\' === DIRECTORY_SEPARATOR` check compared against a constant that does not track the target platform. std::path::MAIN_SEPARATOR and MAIN_SEPARATOR_STR carry the same meaning as PHP's constant and resolve per platform, so the Windows branches are selected on Windows targets. Co-Authored-By: Claude Opus 5 (1M context) --- .../src/symfony/process/executable_finder.rs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'crates/shirabe-external-packages/src/symfony/process/executable_finder.rs') diff --git a/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs b/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs index 3c44b4ad..a00a302c 100644 --- a/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs +++ b/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs @@ -25,7 +25,7 @@ impl ExecutableFinder { pub fn find(&self, name: &str, default: Option<&str>, extra_dirs: &[String]) -> Option { // windows built-in commands that are present in cmd.exe should not be resolved using PATH as they do not exist as exes - if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" + if std::path::MAIN_SEPARATOR == '\\' && CMD_BUILTINS.contains(&shirabe_php_shim::strtolower(name).as_str()) { return Some(name.to_string()); @@ -39,7 +39,7 @@ impl ExecutableFinder { dirs.extend_from_slice(extra_dirs); let mut suffixes: Vec = vec![]; - if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" { + if std::path::MAIN_SEPARATOR == '\\' { let path_ext = shirabe_php_shim::getenv("PATHEXT").map(|v| v.to_string_lossy().into_owned()); suffixes = self.suffixes.clone(); @@ -68,13 +68,9 @@ impl ExecutableFinder { for suffix in &suffixes { for dir in &dirs { let dir = if dir.is_empty() { "." } else { dir.as_str() }; - let file = format!( - "{dir}{}{name}{suffix}", - shirabe_php_shim::DIRECTORY_SEPARATOR - ); + let file = format!("{dir}{}{name}{suffix}", std::path::MAIN_SEPARATOR); if shirabe_php_shim::is_file(&file) - && (shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" - || shirabe_php_shim::is_executable(&file)) + && (std::path::MAIN_SEPARATOR == '\\' || shirabe_php_shim::is_executable(&file)) { return Some(file); } @@ -88,12 +84,9 @@ impl ExecutableFinder { } } - if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" + if std::path::MAIN_SEPARATOR == '\\' || name.len() - != shirabe_php_shim::strcspn( - name, - &format!("/{}", shirabe_php_shim::DIRECTORY_SEPARATOR), - ) + != shirabe_php_shim::strcspn(name, &format!("/{}", std::path::MAIN_SEPARATOR)) { return default.map(ToString::to_string); } -- cgit v1.3.1-4-g156e