diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-07-20 16:51:45 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-07-20 16:51:45 +0900 |
| commit | a2110fa811c8f6c7d1c45a83c6fd1077eb6f3461 (patch) | |
| tree | 620f3cea4ef0c99b5e4a0b7878a59b9e7dbabe36 /crates/shirabe/src/util | |
| parent | 37ed5b8c6d4cda30e668d0221eb281431dbc8c67 (diff) | |
| download | php-shirabe-a2110fa811c8f6c7d1c45a83c6fd1077eb6f3461.tar.gz php-shirabe-a2110fa811c8f6c7d1c45a83c6fd1077eb6f3461.tar.zst php-shirabe-a2110fa811c8f6c7d1c45a83c6fd1077eb6f3461.zip | |
fix(php-shim): use PhpMixed::to_bool() for PHP truthy casts
Several call sites coerced PhpMixed to bool via `.as_bool()` (which
only matches a literal Bool variant) where the corresponding PHP code
does a plain `(bool)` cast or truthy check (isset()/array_key_exists()
+ implicit bool conversion). This silently dropped truthy non-bool
values (e.g. String("true"), String("1"), Int(1)) to their unwrap_or
default instead of PHP's actual truthy result. Switched these sites to
PhpMixed::to_bool(), which implements PHP's full truthy-cast rules.
Diffstat (limited to 'crates/shirabe/src/util')
| -rw-r--r-- | crates/shirabe/src/util/platform.rs | 22 | ||||
| -rw-r--r-- | crates/shirabe/src/util/remote_filesystem.rs | 8 |
2 files changed, 13 insertions, 17 deletions
diff --git a/crates/shirabe/src/util/platform.rs b/crates/shirabe/src/util/platform.rs index 81f2adbb..259d5c95 100644 --- a/crates/shirabe/src/util/platform.rs +++ b/crates/shirabe/src/util/platform.rs @@ -116,12 +116,10 @@ impl Platform { .unwrap_or(""); // Treat HOME as an alias for USERPROFILE on Windows for legacy reasons if Platform::is_windows() && var == "HOME" { - if Platform::get_env("HOME").is_some() { - return format!( - "{}{}", - Platform::get_env("HOME").unwrap_or_default(), - path_part, - ); + let home = + Platform::get_env("HOME").filter(|v| PhpMixed::String(v.clone()).to_bool()); + if let Some(home) = home { + return format!("{}{}", home, path_part); } return format!( @@ -189,9 +187,7 @@ impl Platform { .ok() .flatten() .unwrap_or_default(); - if !(ini_get("open_basedir") - .map(|s| !s.is_empty()) - .unwrap_or(false)) + if !ini_get("open_basedir").is_some_and(|s| PhpMixed::String(s).to_bool()) && is_readable("/proc/version") && stripos(&file_contents, "microsoft").is_some() && !Self::is_docker() @@ -217,10 +213,7 @@ impl Platform { } // cannot check so assume no - if ini_get("open_basedir") - .map(|s| !s.is_empty()) - .unwrap_or(false) - { + if ini_get("open_basedir").is_some_and(|s| PhpMixed::String(s).to_bool()) { *cached = Some(false); return false; } @@ -274,8 +267,7 @@ impl Platform { *use_mb_string = Some( function_exists("mb_strlen") && ini_get("mbstring.func_overload") - .map(|s| !s.is_empty()) - .unwrap_or(false), + .is_some_and(|s| PhpMixed::String(s).to_bool()), ); } diff --git a/crates/shirabe/src/util/remote_filesystem.rs b/crates/shirabe/src/util/remote_filesystem.rs index 08e8581f..103a94a7 100644 --- a/crates/shirabe/src/util/remote_filesystem.rs +++ b/crates/shirabe/src/util/remote_filesystem.rs @@ -194,8 +194,12 @@ impl RemoteFilesystem { self.redirects = 1; // The first request counts. let mut temp_additional_options = additional_options.clone(); - if let Some(v) = temp_additional_options.get("retry-auth-failure").cloned() { - retry_auth_failure = v.as_bool().unwrap_or(true); + if let Some(v) = temp_additional_options + .get("retry-auth-failure") + .and_then(|v| v.as_opt()) + .cloned() + { + retry_auth_failure = v.to_bool(); temp_additional_options.shift_remove("retry-auth-failure"); } |
