1
0
Fork 0

Merge pull request #228 from jakzal/JsonEncodeFix

Fixed json encoding when quoted value contains trailing backslash.
pull/226/merge
Jordi Boggiano 2012-01-19 01:10:36 -08:00
commit 191b8344e9
2 changed files with 10 additions and 1 deletions

View File

@ -130,7 +130,7 @@ class JsonFile
$char = substr($json, $i, 1); $char = substr($json, $i, 1);
// Are we inside a quoted string? // Are we inside a quoted string?
if ('"' === $char && '\\' !== $prevChar) { if ('"' === $char && ('\\' !== $prevChar || '\\\\' === substr($json, $i-2, 2))) {
$outOfQuotes = !$outOfQuotes; $outOfQuotes = !$outOfQuotes;
} elseif (':' === $char && $outOfQuotes) { } elseif (':' === $char && $outOfQuotes) {
// Add a space after the : character // Add a space after the : character

View File

@ -93,6 +93,15 @@ class JsonFileTest extends \PHPUnit_Framework_TestCase
$this->assertJsonFormat($json, $data); $this->assertJsonFormat($json, $data);
} }
public function testTrailingBackslash()
{
$data = array('Metadata\\' => 'src/');
$json = '{
"Metadata\\\\": "src\/"
}';
$this->assertJsonFormat($json, $data);
}
private function expectParseException($text, $json) private function expectParseException($text, $json)
{ {
try { try {