Add detection for unescaped backslashes
parent
f5aa3e6c79
commit
066a0db752
|
@ -124,6 +124,8 @@ class JsonFile
|
||||||
$charOffset = 0;
|
$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';
|
$msg .= ', extra comma';
|
||||||
|
} elseif (preg_match('#(\\\\(?!["\\/bfnrt]|u[a-f0-9]{4}))#i', $json, $match, PREG_OFFSET_CAPTURE)) {
|
||||||
|
$msg .= ', unescaped backslash (\\)';
|
||||||
} elseif (preg_match('#(["}\]]) *\r?\n *"#', $json, $match, PREG_OFFSET_CAPTURE)) {
|
} elseif (preg_match('#(["}\]]) *\r?\n *"#', $json, $match, PREG_OFFSET_CAPTURE)) {
|
||||||
$msg .= ', missing comma';
|
$msg .= ', missing comma';
|
||||||
$charOffset = 1;
|
$charOffset = 1;
|
||||||
|
|
|
@ -34,6 +34,14 @@ class JsonFileTest extends \PHPUnit_Framework_TestCase
|
||||||
$this->expectParseException('extra comma on line 3, char 18', $json);
|
$this->expectParseException('extra comma on line 3, char 18', $json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testParseErrorDetectUnescapedBackslash()
|
||||||
|
{
|
||||||
|
$json = '{
|
||||||
|
"fo\o": "bar"
|
||||||
|
}';
|
||||||
|
$this->expectParseException('unescaped backslash (\\) on line 2, char 12', $json);
|
||||||
|
}
|
||||||
|
|
||||||
public function testParseErrorDetectSingleQuotes()
|
public function testParseErrorDetectSingleQuotes()
|
||||||
{
|
{
|
||||||
$json = '{
|
$json = '{
|
||||||
|
|
Loading…
Reference in New Issue