From e63ccb5cbb479df0f0e5010065ff57bbf4ca238f Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 27 Jun 2026 19:44:01 +0900 Subject: fix(json): encode empty stdClass fields as {} not [] Empty PhpMixed::Array now serializes as [], so the several places that build a PHP `new \stdClass` via an empty Array were emitting [] where Composer writes {}. Use PhpMixed::Object for those empty-object cases: - InitCommand: require / require-dev - Locker::fixupJsonDataType: stability-flags / platform / platform-dev - JsonConfigSource fallback: require/config keys that must stay objects Align the affected test expectations with Composer: JsonFile::read() decodes with assoc=true, collapsing the on-disk {} back to [], so reads expect []. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe/src/command/init_command.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/shirabe/src/command') diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs index ab0e52c..88a2934 100644 --- a/crates/shirabe/src/command/init_command.rs +++ b/crates/shirabe/src/command/init_command.rs @@ -226,8 +226,8 @@ impl Command for InitCommand { .unwrap_or_default(); let formatted = self.format_requirements(req_list)?; if formatted.is_empty() { - // PHP: new \stdClass — represented as an empty IndexMap (JSON object) - PhpMixed::Array(IndexMap::new()) + // PHP: new \stdClass — empty JSON object + PhpMixed::Object(IndexMap::new()) } else { PhpMixed::Array( formatted @@ -238,7 +238,7 @@ impl Command for InitCommand { } } else { // PHP: new \stdClass - PhpMixed::Array(IndexMap::new()) + PhpMixed::Object(IndexMap::new()) }; options.insert("require".to_string(), require_value); @@ -254,7 +254,7 @@ impl Command for InitCommand { .unwrap_or_default(); let formatted = self.format_requirements(req_list)?; let value = if formatted.is_empty() { - PhpMixed::Array(IndexMap::new()) + PhpMixed::Object(IndexMap::new()) } else { PhpMixed::Array( formatted -- cgit v1.3.1