From a30e6109bf24ca5b9ad93c399cd70f2065115d0d Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 29 Apr 2012 21:04:18 +0200 Subject: [PATCH] Fix 5.4.0 interop in formatting of empty array/objects --- src/Composer/Json/JsonFile.php | 2 +- tests/Composer/Test/Json/JsonFileTest.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Composer/Json/JsonFile.php b/src/Composer/Json/JsonFile.php index 695679d1d..16d3d3394 100644 --- a/src/Composer/Json/JsonFile.php +++ b/src/Composer/Json/JsonFile.php @@ -237,7 +237,7 @@ class JsonFile } } else { // Collapse empty {} and [] - $result = rtrim($result); + $result = rtrim($result)."\n\n".$indentStr; } } diff --git a/tests/Composer/Test/Json/JsonFileTest.php b/tests/Composer/Test/Json/JsonFileTest.php index 4e30928cb..159017aa6 100644 --- a/tests/Composer/Test/Json/JsonFileTest.php +++ b/tests/Composer/Test/Json/JsonFileTest.php @@ -128,6 +128,20 @@ class JsonFileTest extends \PHPUnit_Framework_TestCase $this->assertJsonFormat($json, $data); } + public function testFormatEmptyArray() + { + $data = array('test' => array(), 'test2' => new \stdClass); + $json = '{ + "test": [ + + ], + "test2": { + + } +}'; + $this->assertJsonFormat($json, $data); + } + public function testEscape() { $data = array("Metadata\\\"" => 'src/');