From dea4bdf8f0c98dd20fafd5791760769cfb2e55fd Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 13 Jan 2013 17:06:35 +0100 Subject: [PATCH] Expand {} into a new line before manipulating json, fixes #1481 --- src/Composer/Json/JsonManipulator.php | 2 +- tests/Composer/Test/Json/JsonManipulatorTest.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Composer/Json/JsonManipulator.php b/src/Composer/Json/JsonManipulator.php index fd37f681d..c8b662623 100644 --- a/src/Composer/Json/JsonManipulator.php +++ b/src/Composer/Json/JsonManipulator.php @@ -30,7 +30,7 @@ class JsonManipulator throw new \InvalidArgumentException('The json file must be an object ({})'); } $this->newline = false !== strpos("\r\n", $contents) ? "\r\n": "\n"; - $this->contents = $contents; + $this->contents = $contents === '{}' ? '{' . $this->newline . '}' : $contents; $this->detectIndenting(); } diff --git a/tests/Composer/Test/Json/JsonManipulatorTest.php b/tests/Composer/Test/Json/JsonManipulatorTest.php index 8679a7508..4f3b1dd54 100644 --- a/tests/Composer/Test/Json/JsonManipulatorTest.php +++ b/tests/Composer/Test/Json/JsonManipulatorTest.php @@ -30,8 +30,7 @@ class JsonManipulatorTest extends \PHPUnit_Framework_TestCase { return array( array( - '{ -}', + '{}', 'require', 'vendor/baz', 'qux',