From 80631d2fc8d91591c8ce42d158bea24aff86c2af Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 29 Apr 2024 11:19:52 +0200 Subject: [PATCH] Fix one more case of unsetting a key in an object --- src/Composer/Json/JsonManipulator.php | 3 +++ tests/Composer/Test/Command/ConfigCommandTest.php | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/src/Composer/Json/JsonManipulator.php b/src/Composer/Json/JsonManipulator.php index 809cea57a..2e0f70411 100644 --- a/src/Composer/Json/JsonManipulator.php +++ b/src/Composer/Json/JsonManipulator.php @@ -430,6 +430,9 @@ class JsonManipulator if ($subName !== null) { $curVal = json_decode($matches['content'], true); unset($curVal[$name][$subName]); + if ($curVal[$name] === []) { + $curVal[$name] = new \ArrayObject(); + } $childrenClean = $this->format($curVal, 0, true); } diff --git a/tests/Composer/Test/Command/ConfigCommandTest.php b/tests/Composer/Test/Command/ConfigCommandTest.php index 27ee92b4a..cf3a55acc 100644 --- a/tests/Composer/Test/Command/ConfigCommandTest.php +++ b/tests/Composer/Test/Command/ConfigCommandTest.php @@ -82,6 +82,11 @@ class ConfigCommandTest extends TestCase ['setting-key' => 'preferred-install.foo/*', '--unset' => true], ['config' => ['preferred-install' => []]], ]; + yield 'unset platform' => [ + ['config' => ['platform' => ['php' => '7.2.5'], 'platform-check' => false]], + ['setting-key' => 'platform.php', '--unset' => true], + ['config' => ['platform' => [], 'platform-check' => false]], + ]; yield 'set extra with merge' => [ [], ['setting-key' => 'extra.patches.foo/bar', 'setting-value' => ['{"123":"value"}'], '--json' => true, '--merge' => true],