Browse Source

Fix 5.4.0 interop in formatting of empty array/objects

Jordi Boggiano 13 years ago
parent
commit
a30e6109bf
2 changed files with 15 additions and 1 deletions
  1. 1 1
      src/Composer/Json/JsonFile.php
  2. 14 0
      tests/Composer/Test/Json/JsonFileTest.php

+ 1 - 1
src/Composer/Json/JsonFile.php

@@ -237,7 +237,7 @@ class JsonFile
                     }
                 } else {
                     // Collapse empty {} and []
-                    $result = rtrim($result);
+                    $result = rtrim($result)."\n\n".$indentStr;
                 }
             }
 

+ 14 - 0
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/');