Skip to content

Commit 80631d2

Browse files
committed
Fix one more case of unsetting a key in an object
1 parent 877f1b1 commit 80631d2

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/Composer/Json/JsonManipulator.php

+3
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,9 @@ public function removeSubNode(string $mainNode, string $name): bool
430430
if ($subName !== null) {
431431
$curVal = json_decode($matches['content'], true);
432432
unset($curVal[$name][$subName]);
433+
if ($curVal[$name] === []) {
434+
$curVal[$name] = new \ArrayObject();
435+
}
433436
$childrenClean = $this->format($curVal, 0, true);
434437
}
435438

tests/Composer/Test/Command/ConfigCommandTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ public static function provideConfigUpdates(): \Generator
8282
['setting-key' => 'preferred-install.foo/*', '--unset' => true],
8383
['config' => ['preferred-install' => []]],
8484
];
85+
yield 'unset platform' => [
86+
['config' => ['platform' => ['php' => '7.2.5'], 'platform-check' => false]],
87+
['setting-key' => 'platform.php', '--unset' => true],
88+
['config' => ['platform' => [], 'platform-check' => false]],
89+
];
8590
yield 'set extra with merge' => [
8691
[],
8792
['setting-key' => 'extra.patches.foo/bar', 'setting-value' => ['{"123":"value"}'], '--json' => true, '--merge' => true],

0 commit comments

Comments
 (0)