From 79828f7543f355180c6225442404dd833a0252a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Wed, 27 Dec 2017 19:43:31 +0100 Subject: [PATCH 1/2] Enhancement: Assert that key is removed when value is null --- tests/Composer/Test/Json/JsonManipulatorTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/Composer/Test/Json/JsonManipulatorTest.php b/tests/Composer/Test/Json/JsonManipulatorTest.php index e66e9aac2..05de454ca 100644 --- a/tests/Composer/Test/Json/JsonManipulatorTest.php +++ b/tests/Composer/Test/Json/JsonManipulatorTest.php @@ -2310,6 +2310,22 @@ class JsonManipulatorTest extends TestCase ', $manipulator->getContents()); } + public function testRemoveMainKeyRemovesKeyWhereValueIsNull() + { + $manipulator = new JsonManipulator(json_encode(array( + 'foo' => 9000, + 'bar' => null, + ))); + + $manipulator->removeMainKey('bar'); + + $expected = json_encode(array( + 'foo' => 9000, + )); + + $this->assertJsonStringEqualsJsonString($expected, $manipulator->getContents()); + } + public function testIndentDetection() { $manipulator = new JsonManipulator('{ From de07f588c14452e69e0ec2e557739657f3b95892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Wed, 27 Dec 2017 19:49:32 +0100 Subject: [PATCH 2/2] Fix: Use array_key_exists() instead of isset() --- src/Composer/Json/JsonManipulator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Json/JsonManipulator.php b/src/Composer/Json/JsonManipulator.php index f929732fe..cdd22c817 100644 --- a/src/Composer/Json/JsonManipulator.php +++ b/src/Composer/Json/JsonManipulator.php @@ -417,7 +417,7 @@ class JsonManipulator { $decoded = JsonFile::parseJson($this->contents); - if (!isset($decoded[$key])) { + if (!array_key_exists($key, $decoded)) { return true; }