Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15409800
D10433.id25094.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D10433.id25094.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
@@ -26,13 +26,15 @@
{
const DETECT_KEY_CONFLICTS = 1;
const ALLOW_DUPLICATE_KEYS = 2;
+ const PARSE_TO_ASSOC = 4;
+
+ private $lexer;
private $flags;
private $stack;
private $vstack; // semantic value stack
private $lstack; // location stack
- private $yy;
private $symbols = array(
'error' => 2,
'JSONString' => 3,
@@ -358,7 +360,11 @@
case 6:
return $yyval->token = $tokens[$len-1];
case 13:
- $yyval->token = array();
+ if ($this->flags & self::PARSE_TO_ASSOC) {
+ $yyval->token = array();
+ } else {
+ $yyval->token = new stdClass;
+ }
break;
case 14:
$yyval->token = $tokens[$len-1];
@@ -367,22 +373,45 @@
$yyval->token = array($tokens[$len-2], $tokens[$len]);
break;
case 16:
- $yyval->token = array();
$property = $tokens[$len][0];
- $yyval->token[$property] = $tokens[$len][1];
+ if ($this->flags & self::PARSE_TO_ASSOC) {
+ $yyval->token = array();
+ $yyval->token[$property] = $tokens[$len][1];
+ } else {
+ $yyval->token = new stdClass;
+ $yyval->token->$property = $tokens[$len][1];
+ }
break;
case 17:
- $yyval->token = $tokens[$len-2];
- $key = $tokens[$len][0];
- 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) && array_key_exists($key, $tokens[$len-2])) {
- // Forget about it...
+ if ($this->flags & self::PARSE_TO_ASSOC) {
+ $yyval->token =& $tokens[$len-2];
+ $key = $tokens[$len][0];
+ 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])) {
+ // Forget about it...
+ }
+ $tokens[$len-2][$key] = $tokens[$len][1];
+ } else {
+ $yyval->token = $tokens[$len-2];
+ $key = $tokens[$len][0];
+ 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})) {
+ $duplicateCount = 1;
+ do {
+ $duplicateKey = $key . '.' . $duplicateCount++;
+ } while (isset($tokens[$len-2]->$duplicateKey));
+ $key = $duplicateKey;
+ }
+ $tokens[$len-2]->$key = $tokens[$len][1];
}
- $yyval->token[$key] = $tokens[$len][1];
break;
case 18:
$yyval->token = array();
@@ -453,4 +482,4 @@
$this->parseError("BOM detected, make sure your input does not include a Unicode Byte-Order-Mark", array());
}
}
-}
+}
\ No newline at end of file
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,11 +79,7 @@
public function showPosition()
{
$pre = str_replace("\n", '', $this->getPastInput());
- if ($pre) {
- $c = str_repeat('-', strlen($pre) - 1); // new Array(pre.length + 1).join("-");
- } else {
- $c = "";
- }
+ $c = str_repeat('-', max(0, strlen($pre) - 1)); // new Array(pre.length + 1).join("-");
return $pre . str_replace("\n", '', $this->getUpcomingInput()) . "\n" . $c . "^";
}
@@ -148,7 +144,6 @@
);
$this->yytext .= $match[0];
$this->match .= $match[0];
- $this->matches = $match;
$this->yyleng = strlen($this->yytext);
$this->more = false;
$this->input = substr($this->input, strlen($match[0]));
@@ -176,16 +171,6 @@
);
}
- private function begin($condition)
- {
- $this->conditionStack[] = $condition;
- }
-
- private function popState()
- {
- return array_pop($this->conditionStack);
- }
-
private function getCurrentRules()
{
return $this->conditions[$this->conditionStack[count($this->conditionStack)-1]]['rules'];
@@ -193,7 +178,6 @@
private function performAction($avoiding_name_collisions, $YY_START)
{
- $YYSTATE = $YY_START;
switch ($avoiding_name_collisions) {
case 0:/* skip whitespace */
break;
@@ -228,4 +212,4 @@
return 'INVALID';
}
}
-}
+}
\ No newline at end of file
diff --git a/src/parser/PhutilJSONParser.php b/src/parser/PhutilJSONParser.php
--- a/src/parser/PhutilJSONParser.php
+++ b/src/parser/PhutilJSONParser.php
@@ -48,7 +48,7 @@
}
private function getFlags() {
- $flags = 0;
+ $flags = JsonLintJsonParser::PARSE_TO_ASSOC;
if ($this->allowDuplicateKeys) {
$flags |= JsonLintJsonParser::ALLOW_DUPLICATE_KEYS;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Mar 20, 5:21 AM (1 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7450116
Default Alt Text
D10433.id25094.diff (6 KB)
Attached To
Mode
D10433: Update the `JSONLint` API
Attached
Detach File
Event Timeline
Log In to Comment