jenkins-bot has submitted this change and it was merged.

Change subject: Migrate to FormatJson::parse()
......................................................................


Migrate to FormatJson::parse()

Change-Id: I84f8f7d06c68a67e29af94cf01cae2343bf08ffe
---
M i18n/en.json
M i18n/qqq.json
M includes/JCContent.php
3 files changed, 11 insertions(+), 19 deletions(-)

Approvals:
  MaxSem: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/i18n/en.json b/i18n/en.json
index 36d6113..1c99f93 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -5,7 +5,6 @@
                ]
        },
        "jsonconfig-desc": "Allows JSON configuration to be stored in a wiki",
-       "jsonconfig-bad-json": "Unable to parse JSON configuration. Please 
check the syntax.",
        "jsonconfig-duplicate-field": "More than one value \"$1\" found",
        "jsonconfig-err-array": "Parameter \"$1\" must be a list, e.g. 
['value1', 'value2', ...]",
        "jsonconfig-err-array-count": "List \"$1\" has $2 
{{PLURAL:$2|value|values}}, but must have $3 {{PLURAL:$3|value|values}}, the 
same number of values as \"$4\"",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 0254459..3e57c9d 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -13,7 +13,6 @@
                ]
        },
        "jsonconfig-desc": 
"{{desc|name=JsonConfig|url=https://www.mediawiki.org/wiki/Extension:JsonConfig}}";,
-       "jsonconfig-bad-json": "Text on the page is not in a valid JSON format, 
and there is not much more we can do with it.",
        "jsonconfig-duplicate-field": "Field (<code>$1</code>) was present more 
than once but with different capitalization in the JSON, e.g. \"field\" and 
\"Field\".\n\nParameters:\n* $1 - field name",
        "jsonconfig-err-array": "A field named \"$1\" is not a valid 
non-associative array (not a list). Parameters:\n* $1 - field name",
        "jsonconfig-err-array-count": "A list named \"$1\" must have the same 
number of elements as another list. Parameters:\n* $1 - list name\n* $2 - 
number of elements in the list\n* $3 - number of elements it must have\n* $4 - 
name of the other list",
diff --git a/includes/JCContent.php b/includes/JCContent.php
index d37da55..1953d10 100644
--- a/includes/JCContent.php
+++ b/includes/JCContent.php
@@ -116,27 +116,21 @@
         */
        private function parse() {
                $rawText = $this->getNativeData();
-               $data = FormatJson::decode( $rawText, $this->useAssocParsing );
-               if ( $data === null ) {
-                       if ( $this->thorough ) {
-                               // The most common error is the trailing comma 
in a list. Attempt to remove it.
-                               // We have to do it only once, as otherwise 
there could be an edge case like
-                               // ',\n}' being part of a multi-line string 
value, in which case we should fail
-                               $count = 0;
-                               $rawText = preg_replace( '/,[ \t]*([\r\n]*[ 
\t]*[\]}])/', '$1', $rawText, 1, $count );
-                               if ( $count > 0 ) {
-                                       $data = FormatJson::decode( $rawText, 
$this->useAssocParsing );
-                               }
-                       }
-                       if ( $data === null ) {
-                               $this->status->fatal( 'jsonconfig-bad-json' );
-                               return;
-                       }
+               $parseOpts = FormatJson::STRIP_COMMENTS + 
FormatJson::TRY_FIXING;
+               if ( $this->useAssocParsing ) {
+                       $parseOpts += FormatJson::FORCE_ASSOC;
                }
+               $status = FormatJson::parse( $rawText, $parseOpts );
+               if ( !$status->isOK() ) {
+                       $this->status = $status;
+                       return;
+               }
+               $data = $status->getValue();
                if ( !$this->useAssocParsing ) {
                        // @fixme: HACK - need a deep clone of the data
                        // @fixme: but doing (object)(array)$data will 
re-encode empty [] as {}
-                       $this->rawData = FormatJson::decode( $rawText, 
$this->useAssocParsing );
+                       // @performance: re-encoding is likely faster than 
stripping comments in PHP twice
+                       $this->rawData = FormatJson::decode( 
FormatJson::encode( $data, FormatJson::ALL_OK ), true );
                } else {
                        $this->rawData = $data;
                }

-- 
To view, visit https://gerrit.wikimedia.org/r/317299
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I84f8f7d06c68a67e29af94cf01cae2343bf08ffe
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/JsonConfig
Gerrit-Branch: master
Gerrit-Owner: Yurik <yu...@wikimedia.org>
Gerrit-Reviewer: MaxSem <maxsem.w...@gmail.com>
Gerrit-Reviewer: Siebrand <siebr...@kitano.nl>
Gerrit-Reviewer: Yurik <yu...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to