Page MenuHomePhabricator

D9623.id23104.diff
No OneTemporary

D9623.id23104.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
@@ -356,12 +356,16 @@
$yyval->token = false;
break;
case 6:
- return $yyval->token = $tokens[$len-1];
+ $yyval->token = $tokens[$len-1];
+ if ($yyval->token instanceof stdClass) {
+ $yyval->token = (array)$yyval->token;
+ }
+ return $yyval->token;
case 13:
$yyval->token = new stdClass;
break;
case 14:
- $yyval->token = $tokens[$len-1];
+ $yyval->token = (array)$tokens[$len-1];
break;
case 15:
$yyval->token = array($tokens[$len-2], $tokens[$len]);
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
Wed, Apr 9, 4:30 PM (2 w, 4 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7738133
Default Alt Text
D9623.id23104.diff (2 KB)

Event Timeline