From 633a250e3039d766af3ed5733fe9b825b994511c Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 29 Jun 2026 03:15:40 +0900 Subject: 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 --- crates/shirabe/src/json/json_manipulator.rs | 12 ++++-------- 1 file 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); } -- cgit v1.3.1