Fixed json encoding when quoted value contained trailing backslash.
Condition checking if current character is inside a quoted string did not consider the case when backslash before quote is escaped with another backslash.pull/228/head
parent
4dee2528e9
commit
c680ec7e51
|
@ -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
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue