Jackmcbarn has uploaded a new change for review. https://gerrit.wikimedia.org/r/188883
Change subject: Don't expose TRY_FIXING ...................................................................... Don't expose TRY_FIXING In new code, I don't see the value in decoding things that happen to look like JSON but aren't actually JSON. It promotes bad code and data, and it'll lead to not-quite-JSON ending up all over the place if anyone were to use it. Change-Id: Ib455813cdb39af7437c65ae7b3078afeab18b42b --- M engines/LuaCommon/TextLibrary.php M engines/LuaCommon/lualib/mw.text.lua M tests/engines/LuaCommon/TextLibraryTests.lua 3 files changed, 3 insertions(+), 15 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Scribunto refs/changes/83/188883/1 diff --git a/engines/LuaCommon/TextLibrary.php b/engines/LuaCommon/TextLibrary.php index e6f4aa6..48aa942 100644 --- a/engines/LuaCommon/TextLibrary.php +++ b/engines/LuaCommon/TextLibrary.php @@ -3,8 +3,7 @@ class Scribunto_LuaTextLibrary extends Scribunto_LuaLibraryBase { // Matches Lua mw.text constants const JSON_PRESERVE_KEYS = 1; - const JSON_TRY_FIXING = 2; - const JSON_PRETTY = 4; + const JSON_PRETTY = 2; function register() { global $wgUrlProtocols; @@ -87,11 +86,7 @@ $this->checkType( 'mw.text.jsonDecode', 1, $s, 'string' ); $this->checkTypeOptional( 'mw.text.jsonDecode', 2, $flags, 'number', 0 ); $flags = (int)$flags; - $opts = FormatJson::FORCE_ASSOC; - if ( $flags & self::JSON_TRY_FIXING ) { - $opts |= FormatJson::TRY_FIXING; - } - $status = FormatJson::parse( $s, $opts ); + $status = FormatJson::parse( $s, FormatJson::FORCE_ASSOC ); if ( !$status->isOk() ) { throw new Scribunto_LuaError( 'mw.text.jsonDecode: ' . $status->getMessage()->text() ); } diff --git a/engines/LuaCommon/lualib/mw.text.lua b/engines/LuaCommon/lualib/mw.text.lua index c452384..c1dba4b 100644 --- a/engines/LuaCommon/lualib/mw.text.lua +++ b/engines/LuaCommon/lualib/mw.text.lua @@ -324,7 +324,6 @@ -- Matches PHP Scribunto_LuaTextLibrary constants mwtext.JSON_PRESERVE_KEYS = 1 -mwtext.JSON_TRY_FIXING = 2 -mwtext.JSON_PRETTY = 4 +mwtext.JSON_PRETTY = 2 return mwtext diff --git a/tests/engines/LuaCommon/TextLibraryTests.lua b/tests/engines/LuaCommon/TextLibraryTests.lua index 522fcd2..bc8ed1e 100644 --- a/tests/engines/LuaCommon/TextLibraryTests.lua +++ b/tests/engines/LuaCommon/TextLibraryTests.lua @@ -466,16 +466,10 @@ args = { { [1/0] = 1 } }, expect = 'mw.text.jsonEncode: Cannot use \'inf\' as a table key' }, - { name = 'json decode, invalid values (trailing comma)', func = mw.text.jsonDecode, args = { '{"x":1,}' }, expect = 'mw.text.jsonDecode: Syntax error' - }, - { name = 'json decode, trailing comma with JSON_TRY_FIXING', - func = mw.text.jsonDecode, - args = { '{"x":1,}', mw.text.JSON_TRY_FIXING }, - expect = { { x = 1 } } }, } -- To view, visit https://gerrit.wikimedia.org/r/188883 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib455813cdb39af7437c65ae7b3078afeab18b42b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Scribunto Gerrit-Branch: master Gerrit-Owner: Jackmcbarn <jackmcb...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits