aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-29 03:15:40 +0900
committernsfisis <nsfisis@gmail.com>2026-06-29 03:15:40 +0900
commit633a250e3039d766af3ed5733fe9b825b994511c (patch)
treedd40d55159217a3680f174e23cb0cb05017556a6 /crates/shirabe
parent27e02b6c8968f89cf601ef597fcefa6a9627718e (diff)
downloadphp-shirabe-633a250e3039d766af3ed5733fe9b825b994511c.tar.gz
php-shirabe-633a250e3039d766af3ed5733fe9b825b994511c.tar.zst
php-shirabe-633a250e3039d766af3ed5733fe9b825b994511c.zip
fix(json): use php_truthy for JsonManipulator content validity guards
The `!@json_decode($children)` guards in addSubNode/removeSubNode were translated as `is_null() || as_bool() == Some(false)`, which drops PHP's other falsy cases (empty array/string, "0", 0). At the removeSubNode site (assoc=true) this diverged from Composer: an empty object node decodes to an empty array, which PHP treats as falsy and aborts on, but the Rust guard kept going. Replace both with php_truthy, the faithful rendering of PHP `!`, preserving the deliberate empty-`{}` behavior difference between the assoc=false (addSubNode) and assoc=true (removeSubNode) sites. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe')
-rw-r--r--crates/shirabe/src/json/json_manipulator.rs12
1 files changed, 4 insertions, 8 deletions
diff --git a/crates/shirabe/src/json/json_manipulator.rs b/crates/shirabe/src/json/json_manipulator.rs
index 043534d..b11178f 100644
--- a/crates/shirabe/src/json/json_manipulator.rs
+++ b/crates/shirabe/src/json/json_manipulator.rs
@@ -8,8 +8,8 @@ use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
InvalidArgumentException, LogicException, PhpMixed, addcslashes, array_key_exists, array_keys,
array_reverse, empty, explode, implode, in_array, is_array, is_int, is_numeric, json_decode,
- preg_quote, rtrim, str_contains, str_repeat, str_replace, strlen, strnatcmp, strpos, substr,
- trim, uksort,
+ php_truthy, preg_quote, rtrim, str_contains, str_repeat, str_replace, strlen, strnatcmp,
+ strpos, substr, trim, uksort,
};
#[derive(Debug)]
@@ -702,9 +702,7 @@ impl JsonManipulator {
let node_end = self.contents[node.value_end..].to_string();
let mut children = self.contents[node.value_pos..node.value_end].to_string();
// invalid match due to un-regexable content, abort
- if json_decode(&children, false)?.is_null()
- || json_decode(&children, false)?.as_bool() == Some(false)
- {
+ if !php_truthy(&json_decode(&children, false)?) {
return Ok(false);
}
@@ -854,9 +852,7 @@ impl JsonManipulator {
let children = self.contents[node.value_pos..node.value_end].to_string();
// invalid match due to un-regexable content, abort
- if json_decode(&children, true)?.is_null()
- || json_decode(&children, true)?.as_bool() == Some(false)
- {
+ if !php_truthy(&json_decode(&children, true)?) {
return Ok(false);
}