Anomie has uploaded a new change for review.
https://gerrit.wikimedia.org/r/52192
Change subject: (bug 45655) Fix mw.uri error with empty fragment or query string
......................................................................
(bug 45655) Fix mw.uri error with empty fragment or query string
Off-by-one error.
Bug: 45655
Change-Id: Ic6e0dfe8dbf392b1fe9e225f7906b4dd84f4febf
---
M engines/LuaCommon/lualib/mw.uri.lua
M tests/engines/LuaCommon/UriLibraryTests.lua
2 files changed, 12 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Scribunto
refs/changes/92/52192/1
diff --git a/engines/LuaCommon/lualib/mw.uri.lua
b/engines/LuaCommon/lualib/mw.uri.lua
index d33f0c6..77750bb 100644
--- a/engines/LuaCommon/lualib/mw.uri.lua
+++ b/engines/LuaCommon/lualib/mw.uri.lua
@@ -453,12 +453,12 @@
checkTypeForIndex( key, value, 'string' )
local i, j = nil, string.len( value )
i = string.find( value, '#', 1, true )
- if i and i < j then
+ if i and i <= j then
fragment = string.sub( value, i + 1, j )
j = i - 1
end
i = string.find( value, '?', 1, true )
- if i and i < j then
+ if i and i <= j then
query = uri.parseQueryString( string.sub(
value, i + 1, j ) )
j = i - 1
end
diff --git a/tests/engines/LuaCommon/UriLibraryTests.lua
b/tests/engines/LuaCommon/UriLibraryTests.lua
index b13e721..145511e 100644
--- a/tests/engines/LuaCommon/UriLibraryTests.lua
+++ b/tests/engines/LuaCommon/UriLibraryTests.lua
@@ -101,6 +101,16 @@
args = { 'Example', { action = 'edit' } },
expect = { 'http://wiki.local/w/index.php?title=Example&action=edit'
},
},
+
+ { name = 'uri.new with empty query string', func = mw.uri.new, type =
'ToString',
+ args = { 'http://wiki.local/w/index.php?' },
+ expect = { 'http://wiki.local/w/index.php?' },
+ },
+
+ { name = 'uri.new with empty fragment', func = mw.uri.new, type =
'ToString',
+ args = { 'http://wiki.local/w/index.php#' },
+ expect = { 'http://wiki.local/w/index.php#' },
+ },
}
-- Add tests to test round-tripping for every combination of parameters
--
To view, visit https://gerrit.wikimedia.org/r/52192
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic6e0dfe8dbf392b1fe9e225f7906b4dd84f4febf
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Scribunto
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits