Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14028532
D9623.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D9623.diff
View Options
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) && array_key_exists($key, $tokens[$len-2])) {
$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) && array_key_exists($key, $tokens[$len-2])) {
$duplicateCount = 1;
do {
$duplicateKey = $key . '.' . $duplicateCount++;
- } while (isset($tokens[$len-2]->$duplicateKey));
+ } while (array_key_exists($duplicateKey, $tokens[$len-2]));
$key = $duplicateKey;
}
- $tokens[$len-2]->$key = $tokens[$len][1];
+ $yyval->token[$key] = $tokens[$len][1];
break;
case 18:
$yyval->token = array();
diff --git a/externals/jsonlint/src/Seld/JsonLint/Lexer.php b/externals/jsonlint/src/Seld/JsonLint/Lexer.php
--- a/externals/jsonlint/src/Seld/JsonLint/Lexer.php
+++ b/externals/jsonlint/src/Seld/JsonLint/Lexer.php
@@ -79,7 +79,11 @@
public function showPosition()
{
$pre = str_replace("\n", '', $this->getPastInput());
- $c = str_repeat('-', strlen($pre) - 1); // new Array(pre.length + 1).join("-");
+ if ($pre) {
+ $c = str_repeat('-', strlen($pre) - 1); // new Array(pre.length + 1).join("-");
+ } else {
+ $c = "";
+ }
return $pre . str_replace("\n", '', $this->getUpcomingInput()) . "\n" . $c . "^";
}
diff --git a/src/parser/PhutilJSONParser.php b/src/parser/PhutilJSONParser.php
--- a/src/parser/PhutilJSONParser.php
+++ b/src/parser/PhutilJSONParser.php
@@ -15,13 +15,6 @@
require_once($jsonlint_root.'/src/Seld/JsonLint/ParsingException.php');
require_once($jsonlint_root.'/src/Seld/JsonLint/Undefined.php');
- if (!$json) {
- throw new PhutilJSONParserException(
- pht(
- '%s is not a valid JSON object.',
- PhutilReadableSerializer::printShort($json)));
- }
-
$parser = new JsonLintJsonParser();
try {
$output = $parser->parse($json);
@@ -29,14 +22,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
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 9, 2:02 PM (4 d, 16 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6722691
Default Alt Text
D9623.diff (4 KB)
Attached To
Mode
D9623: Modify the JsonLint library to return `array` instead of `stdClass`.
Attached
Detach File
Event Timeline
Log In to Comment