diff --git a/src/Composer/Json/JsonFile.php b/src/Composer/Json/JsonFile.php index 03c85250e..fd43c9148 100644 --- a/src/Composer/Json/JsonFile.php +++ b/src/Composer/Json/JsonFile.php @@ -130,7 +130,7 @@ class JsonFile $char = substr($json, $i, 1); // Are we inside a quoted string? - if ('"' === $char && '\\' !== $prevChar) { + if ('"' === $char && ('\\' !== $prevChar || '\\\\' === substr($json, $i-2, 2))) { $outOfQuotes = !$outOfQuotes; } elseif (':' === $char && $outOfQuotes) { // Add a space after the : character diff --git a/tests/Composer/Test/Json/JsonFileTest.php b/tests/Composer/Test/Json/JsonFileTest.php index 75e798388..231839416 100644 --- a/tests/Composer/Test/Json/JsonFileTest.php +++ b/tests/Composer/Test/Json/JsonFileTest.php @@ -93,6 +93,15 @@ class JsonFileTest extends \PHPUnit_Framework_TestCase $this->assertJsonFormat($json, $data); } + public function testTrailingBackslash() + { + $data = array('Metadata\\' => 'src/'); + $json = '{ + "Metadata\\\\": "src\/" +}'; + $this->assertJsonFormat($json, $data); + } + private function expectParseException($text, $json) { try {