Anomie has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/374329 )
Change subject: Make mw.uri.encode 'WIKI' mode match core {{urlencode:}} ...................................................................... Make mw.uri.encode 'WIKI' mode match core {{urlencode:}} The core {{urlencode:}} parser function doesn't encode various characters in WIKI mode that it does in other modes. mw.uri.encode should match that. Bug: T174239 Change-Id: I2be0811cf39c02c5c0ad3433e4b0ef9030350e24 --- M engines/LuaCommon/lualib/mw.uri.lua M tests/phpunit/engines/LuaCommon/UriLibraryTests.lua 2 files changed, 18 insertions(+), 7 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Scribunto refs/changes/29/374329/1 diff --git a/engines/LuaCommon/lualib/mw.uri.lua b/engines/LuaCommon/lualib/mw.uri.lua index 6d01b05..ff00eae 100644 --- a/engines/LuaCommon/lualib/mw.uri.lua +++ b/engines/LuaCommon/lualib/mw.uri.lua @@ -35,6 +35,17 @@ return ret end +local function wikiencode( s ) + local ret = string.gsub( s, '([^a-zA-Z0-9!$()*,./:;@~_-])', function ( c ) + if c == ' ' then + return '_' + else + return string.format( '%%%02X', string.byte( c, 1, 1 ) ) + end + end ); + return ret +end + local function rawdecode( s ) local ret = string.gsub( s, '%%(%x%x)', function ( hex ) return string.char( tonumber( hex, 16 ) ) @@ -51,7 +62,7 @@ elseif enctype == 'PATH' then return rawencode( s, '%20' ) elseif enctype == 'WIKI' then - return rawencode( s, '_' ) + return wikiencode( s ) else error( "bad argument #2 to 'encode' (expected QUERY, PATH, or WIKI)", 2 ) end diff --git a/tests/phpunit/engines/LuaCommon/UriLibraryTests.lua b/tests/phpunit/engines/LuaCommon/UriLibraryTests.lua index c01fa2e..7bf68c9 100644 --- a/tests/phpunit/engines/LuaCommon/UriLibraryTests.lua +++ b/tests/phpunit/engines/LuaCommon/UriLibraryTests.lua @@ -18,16 +18,16 @@ expect = { '__foo+b%C3%A1r+%2B+baz__' } }, { name = 'uri.encode QUERY', func = mw.uri.encode, - args = { '__foo b\195\161r + baz__', 'QUERY' }, - expect = { '__foo+b%C3%A1r+%2B+baz__' } + args = { '__foo b\195\161r + /baz/__', 'QUERY' }, + expect = { '__foo+b%C3%A1r+%2B+%2Fbaz%2F__' } }, { name = 'uri.encode PATH', func = mw.uri.encode, - args = { '__foo b\195\161r + baz__', 'PATH' }, - expect = { '__foo%20b%C3%A1r%20%2B%20baz__' } + args = { '__foo b\195\161r + /baz/__', 'PATH' }, + expect = { '__foo%20b%C3%A1r%20%2B%20%2Fbaz%2F__' } }, { name = 'uri.encode WIKI', func = mw.uri.encode, - args = { '__foo b\195\161r + baz__', 'WIKI' }, - expect = { '__foo_b%C3%A1r_%2B_baz__' } + args = { '__foo b\195\161r + /baz/__', 'WIKI' }, + expect = { '__foo_b%C3%A1r_%2B_/baz/__' } }, { name = 'uri.decode', func = mw.uri.decode, -- To view, visit https://gerrit.wikimedia.org/r/374329 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2be0811cf39c02c5c0ad3433e4b0ef9030350e24 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Scribunto Gerrit-Branch: master Gerrit-Owner: Anomie <bjor...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits