Jelajahi Sumber

Fix 5.4.0 interop in formatting of empty array/objects

Jordi Boggiano 13 tahun lalu
induk
melakukan
a30e6109bf
2 mengubah file dengan 15 tambahan dan 1 penghapusan
  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 {
                 } else {
                     // Collapse empty {} and []
                     // 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);
         $this->assertJsonFormat($json, $data);
     }
     }
 
 
+    public function testFormatEmptyArray()
+    {
+        $data = array('test' => array(), 'test2' => new \stdClass);
+        $json = '{
+    "test": [
+
+    ],
+    "test2": {
+
+    }
+}';
+        $this->assertJsonFormat($json, $data);
+    }
+
     public function testEscape()
     public function testEscape()
     {
     {
         $data = array("Metadata\\\"" => 'src/');
         $data = array("Metadata\\\"" => 'src/');