Page MenuHomePhabricator

D9623.id23107.diff
No OneTemporary

D9623.id23107.diff

diff --git a/externals/jsonlint/src/Seld/JsonLint/JsonParser.php b/externals/jsonlint/src/Seld/JsonLint/JsonParser.php
--- a/externals/jsonlint/src/Seld/JsonLint/JsonParser.php
+++ b/externals/jsonlint/src/Seld/JsonLint/JsonParser.php
@@ -358,7 +358,7 @@
case 6:
return $yyval->token = $tokens[$len-1];
case 13:
- $yyval->token = new stdClass;
+ $yyval->token = array();
break;
case 14:
$yyval->token = $tokens[$len-1];
@@ -367,26 +367,26 @@
$yyval->token = array($tokens[$len-2], $tokens[$len]);
break;
case 16:
- $yyval->token = new stdClass;
+ $yyval->token = array();
$property = $tokens[$len][0] === '' ? '_empty_' : $tokens[$len][0];
- $yyval->token->$property = $tokens[$len][1];
+ $yyval->token[$property] = $tokens[$len][1];
break;
case 17:
$yyval->token = $tokens[$len-2];
$key = $tokens[$len][0] === '' ? '_empty_' : $tokens[$len][0];
- if (($this->flags & self::DETECT_KEY_CONFLICTS) && isset($tokens[$len-2]->{$key})) {
+ if (($this->flags & self::DETECT_KEY_CONFLICTS) && isset($tokens[$len-2][$key])) {
$errStr = 'Parse error on line ' . ($yylineno+1) . ":\n";
$errStr .= $this->lexer->showPosition() . "\n";
$errStr .= "Duplicate key: ".$tokens[$len][0];
throw new JsonLintParsingException($errStr);
- } elseif (($this->flags & self::ALLOW_DUPLICATE_KEYS) && isset($tokens[$len-2]->{$key})) {
+ } elseif (($this->flags & self::ALLOW_DUPLICATE_KEYS) && isset($tokens[$len-2][$key])) {
$duplicateCount = 1;
do {
$duplicateKey = $key . '.' . $duplicateCount++;
} while (isset($tokens[$len-2]->$duplicateKey));
$key = $duplicateKey;
}
- $tokens[$len-2]->$key = $tokens[$len][1];
+ $tokens[$len-2][$key] = $tokens[$len][1];
break;
case 18:
$yyval->token = array();
diff --git a/src/parser/PhutilJSONParser.php b/src/parser/PhutilJSONParser.php
--- a/src/parser/PhutilJSONParser.php
+++ b/src/parser/PhutilJSONParser.php
@@ -29,14 +29,14 @@
throw new PhutilJSONParserException($ex->getMessage());
}
- if (!$output instanceof stdClass && !is_array($output)) {
+ if (!is_array($output)) {
throw new PhutilJSONParserException(
pht(
'%s is not a valid JSON object.',
PhutilReadableSerializer::printShort($json)));
}
- return (array)$output;
+ return $output;
}
}
diff --git a/src/parser/__tests__/PhutilJSONParserTestCase.php b/src/parser/__tests__/PhutilJSONParserTestCase.php
--- a/src/parser/__tests__/PhutilJSONParserTestCase.php
+++ b/src/parser/__tests__/PhutilJSONParserTestCase.php
@@ -10,6 +10,11 @@
'[]' => array(),
'{"foo": "bar"}' => array('foo' => 'bar'),
'[1, "foo", true, null]' => array(1, 'foo', true, null),
+ '{"foo": {"bar": "baz"}}' => array('foo' => array('bar' => 'baz')),
+ '{"foo": "bar", "bar": ["baz"]}'
+ => array('foo' => 'bar', 'bar' => array('baz')),
+ '{"foo": "bar", "bar": {"baz": "foo"}}'
+ => array('foo' => 'bar', 'bar' => array('baz' => 'foo')),
);
foreach ($tests as $input => $expect) {

File Metadata

Mime Type
text/plain
Expires
Mon, Oct 21, 1:57 PM (3 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6716541
Default Alt Text
D9623.id23107.diff (3 KB)

Event Timeline