1
0
Fork 0

Add detection for extra commas in arrays

pull/33/merge
Jordi Boggiano 2011-11-01 14:13:22 +01:00
parent 6f1dab6233
commit f5aa3e6c79
2 changed files with 11 additions and 1 deletions

View File

@ -122,7 +122,7 @@ class JsonFile
case JSON_ERROR_SYNTAX:
$msg = 'Syntax error';
$charOffset = 0;
if (preg_match('#["}\]]\s*(,)\s*\}#', $json, $match, PREG_OFFSET_CAPTURE)) {
if (preg_match('#["}\]]\s*(,)\s*[}\]]#', $json, $match, PREG_OFFSET_CAPTURE)) {
$msg .= ', extra comma';
} elseif (preg_match('#(["}\]]) *\r?\n *"#', $json, $match, PREG_OFFSET_CAPTURE)) {
$msg .= ', missing comma';

View File

@ -24,6 +24,16 @@ class JsonFileTest extends \PHPUnit_Framework_TestCase
$this->expectParseException('extra comma on line 2, char 21', $json);
}
public function testParseErrorDetectExtraCommaInArray()
{
$json = '{
"foo": [
"bar",
]
}';
$this->expectParseException('extra comma on line 3, char 18', $json);
}
public function testParseErrorDetectSingleQuotes()
{
$json = '{