diff --git a/src/Composer/Json/JsonManipulator.php b/src/Composer/Json/JsonManipulator.php index 0ca020ad7..3fd45012c 100644 --- a/src/Composer/Json/JsonManipulator.php +++ b/src/Composer/Json/JsonManipulator.php @@ -204,6 +204,11 @@ class JsonManipulator list($name, $subName) = explode('.', $name, 2); } + // no node to remove + if (!isset($decoded[$mainNode][$name]) || ($subName && !isset($decoded[$mainNode][$name][$subName]))) { + return true; + } + // try and find a match for the subkey if ($this->pregMatch('{"'.preg_quote($name).'"\s*:}i', $children)) { // find best match for the value of "name" diff --git a/tests/Composer/Test/Json/JsonManipulatorTest.php b/tests/Composer/Test/Json/JsonManipulatorTest.php index 9b55efb2d..31ef70f24 100644 --- a/tests/Composer/Test/Json/JsonManipulatorTest.php +++ b/tests/Composer/Test/Json/JsonManipulatorTest.php @@ -368,6 +368,50 @@ class JsonManipulatorTest extends \PHPUnit_Framework_TestCase } } } +' + ), + 'works on child having unmatched name' => array( + '{ + "repositories": { + "baz": { + "foo": "bar", + "bar": "baz" + } + } +}', + 'bar', + true, + '{ + "repositories": { + "baz": { + "foo": "bar", + "bar": "baz" + } + } +} +' + ), + 'works on child having duplicate name' => array( + '{ + "repositories": { + "foo": { + "baz": "qux" + }, + "baz": { + "foo": "bar", + "bar": "baz" + } + } +}', + 'baz', + true, + '{ + "repositories": { + "foo": { + "baz": "qux" + } + } +} ' ), 'works on empty repos' => array(