aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-09 06:50:56 +0900
committernsfisis <nsfisis@gmail.com>2026-08-09 06:50:56 +0900
commit6b83e68d7961f150ec15dd59d457d519e0bf8663 (patch)
tree8342c9d7d31679c669e14a76d0349c777f6c2566
parentff17dcdb757656c5e81b10070a7bbcc4ef3e97f7 (diff)
downloadphp-shirabe-6b83e68d7961f150ec15dd59d457d519e0bf8663.tar.gz
php-shirabe-6b83e68d7961f150ec15dd59d457d519e0bf8663.tar.zst
php-shirabe-6b83e68d7961f150ec15dd59d457d519e0bf8663.zip
refactor(env): split and join PATH lists with std::env
The shim's PATH_SEPARATOR was hardcoded to ":", so every PATH list was split and joined on the wrong character off Unix. std::env::split_paths and join_paths use the platform's separator, which also lets the bin-dir membership test in EventDispatcher compare list entries instead of regex-matching the raw PATH string. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
-rw-r--r--crates/shirabe-external-packages/src/symfony/process/executable_finder.rs10
-rw-r--r--crates/shirabe-php-shim/src/fs.rs2
-rw-r--r--crates/shirabe/src/event_dispatcher/event_dispatcher.rs25
-rw-r--r--crates/shirabe/tests/util/ini_helper_test.rs9
4 files changed, 24 insertions, 22 deletions
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 309cdf7e..5b1c0994 100644
--- a/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs
+++ b/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs
@@ -33,7 +33,9 @@ impl ExecutableFinder {
.or_else(|| shirabe_php_shim::getenv("Path"))
.map(|v| v.to_string_lossy().into_owned())
.unwrap_or_default();
- let mut dirs = shirabe_php_shim::explode(shirabe_php_shim::PATH_SEPARATOR, &path);
+ let mut dirs: Vec<String> = std::env::split_paths(&path)
+ .map(|dir| dir.into_os_string().into_string().unwrap())
+ .collect();
dirs.extend_from_slice(extra_dirs);
let mut suffixes: Vec<String> = vec![];
@@ -42,9 +44,9 @@ impl ExecutableFinder {
shirabe_php_shim::getenv("PATHEXT").map(|v| v.to_string_lossy().into_owned());
suffixes = self.suffixes.clone();
let exts = match path_ext {
- Some(ref ext) if !ext.is_empty() => {
- shirabe_php_shim::explode(shirabe_php_shim::PATH_SEPARATOR, ext)
- }
+ Some(ref ext) if !ext.is_empty() => std::env::split_paths(ext)
+ .map(|e| e.into_os_string().into_string().unwrap())
+ .collect(),
_ => vec![
".exe".to_string(),
".bat".to_string(),
diff --git a/crates/shirabe-php-shim/src/fs.rs b/crates/shirabe-php-shim/src/fs.rs
index 575ce26a..7a8114bb 100644
--- a/crates/shirabe-php-shim/src/fs.rs
+++ b/crates/shirabe-php-shim/src/fs.rs
@@ -19,8 +19,6 @@ pub const PATHINFO_EXTENSION: i64 = 4;
pub const PATHINFO_DIRNAME: i64 = 1;
pub const PATHINFO_BASENAME: i64 = 2;
-pub const PATH_SEPARATOR: &str = ":";
-
/// PHP `PHP_MAXPATHLEN`: the platform's `MAXPATHLEN` (`MAX_PATH` on Windows).
pub const PHP_MAXPATHLEN: i64 = if cfg!(windows) {
260
diff --git a/crates/shirabe/src/event_dispatcher/event_dispatcher.rs b/crates/shirabe/src/event_dispatcher/event_dispatcher.rs
index 3db924d4..f037f87d 100644
--- a/crates/shirabe/src/event_dispatcher/event_dispatcher.rs
+++ b/crates/shirabe/src/event_dispatcher/event_dispatcher.rs
@@ -31,7 +31,7 @@ use shirabe_php_rpc::{
};
use shirabe_php_shim::Catch as _;
use shirabe_php_shim::{
- InvalidArgumentException, PATH_SEPARATOR, PhpMixed, RuntimeException, array_pop, array_push,
+ InvalidArgumentException, PhpMixed, RuntimeException, array_pop, array_push,
array_search_in_vec, array_splice, file_exists, get_class, hash, implode, ini_get, is_array,
is_callable, is_object, is_string, krsort, php_regex, preg_quote, realpath,
spl_autoload_functions, spl_autoload_register, spl_autoload_unregister, spl_object_hash,
@@ -1413,19 +1413,16 @@ try {{
if shirabe_php_shim::is_dir(&bin_dir) {
let bin_dir = realpath(&bin_dir).unwrap_or(bin_dir);
let path_value = Platform::get_env(path_env).unwrap_or_default();
- if !Preg::is_match(
- format!(
- "{{(^|{}){}($|{})}}",
- PATH_SEPARATOR,
- preg_quote(&bin_dir, None),
- PATH_SEPARATOR
- ),
- &path_value,
- ) {
- Platform::put_env(
- path_env,
- &format!("{}{}{}", bin_dir, PATH_SEPARATOR, path_value),
- );
+ if !std::env::split_paths(&path_value).any(|dir| dir == std::path::Path::new(&bin_dir))
+ {
+ let path_value = std::env::join_paths(
+ std::iter::once(std::path::PathBuf::from(&bin_dir))
+ .chain(std::env::split_paths(&path_value)),
+ )
+ .expect("bin-dir holds no path separator")
+ .into_string()
+ .unwrap();
+ Platform::put_env(path_env, &path_value);
}
}
}
diff --git a/crates/shirabe/tests/util/ini_helper_test.rs b/crates/shirabe/tests/util/ini_helper_test.rs
index 0b3835a0..90015169 100644
--- a/crates/shirabe/tests/util/ini_helper_test.rs
+++ b/crates/shirabe/tests/util/ini_helper_test.rs
@@ -2,7 +2,7 @@
use shirabe::util::ini_helper::IniHelper;
use shirabe::util::platform::Platform;
-use shirabe_php_shim::{PATH_SEPARATOR, getenv, putenv};
+use shirabe_php_shim::{getenv, putenv};
#[allow(dead_code)]
fn set_up() -> TearDown {
@@ -39,7 +39,12 @@ impl Drop for TearDown {
}
fn set_env(paths: &[&str]) {
- unsafe { putenv("COMPOSER_ORIGINAL_INIS", paths.join(PATH_SEPARATOR)) };
+ unsafe {
+ putenv(
+ "COMPOSER_ORIGINAL_INIS",
+ std::env::join_paths(paths).unwrap(),
+ )
+ };
}
#[test]