Anomie has uploaded a new change for review.
https://gerrit.wikimedia.org/r/203975
Change subject: ustring: Handle empty charset like Lua does
......................................................................
ustring: Handle empty charset like Lua does
Both '[]' and '[^]' give a rather odd error, but it's probably best to
follow suit.
Bug: T95958
Change-Id: I3310da55f655537c9082fc9039003f6b2d31eff4
---
M engines/LuaCommon/UstringLibrary.php
M engines/LuaCommon/lualib/ustring/ustring.lua
M tests/engines/LuaCommon/UstringLibraryTests.lua
3 files changed, 16 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Scribunto
refs/changes/75/203975/1
diff --git a/engines/LuaCommon/UstringLibrary.php
b/engines/LuaCommon/UstringLibrary.php
index 857df34..7463bbd 100644
--- a/engines/LuaCommon/UstringLibrary.php
+++ b/engines/LuaCommon/UstringLibrary.php
@@ -463,6 +463,10 @@
$re .= preg_quote( $pat[$i], '/' );
}
}
+ if ( $re === '[' || $re === '[^' ) {
+ // This is the error Lua string functions throws in
this situation
+ throw new Scribunto_LuaError( "malformed pattern
(missing ']')" );
+ }
if ( $i >= $len ) {
throw new Scribunto_LuaError( "Missing close-bracket
for character set beginning at pattern character $ii" );
}
diff --git a/engines/LuaCommon/lualib/ustring/ustring.lua
b/engines/LuaCommon/lualib/ustring/ustring.lua
index a4b4088..57456ac 100644
--- a/engines/LuaCommon/lualib/ustring/ustring.lua
+++ b/engines/LuaCommon/lualib/ustring/ustring.lua
@@ -567,6 +567,10 @@
epp = ep + 1
until S.byte( rawpat, ep - 1 ) ~= 0x25 or S.byte( rawpat, ep -
2 ) == 0x25
local key = S.sub( rawpat, pattern.bytepos[pp], ep )
+ if key == '[]' or key == '[^]' then
+ -- This is the error Lua string functions throws in
this situation
+ error( "malformed pattern (missing ']')" )
+ end
if charset_cache[key] then
local pl, cs = unpack( charset_cache[key] )
return pp + pl, cs
diff --git a/tests/engines/LuaCommon/UstringLibraryTests.lua
b/tests/engines/LuaCommon/UstringLibraryTests.lua
index 87de8f4..bc81350 100644
--- a/tests/engines/LuaCommon/UstringLibraryTests.lua
+++ b/tests/engines/LuaCommon/UstringLibraryTests.lua
@@ -429,6 +429,14 @@
args = { "fóó", '([^a-z])' },
expect = { 2, 2, 'ó' }
},
+ { name = 'find: empty character set', func = mw.ustring.find,
+ args = { "fóó", '[]' },
+ expect = "malformed pattern (missing ']')"
+ },
+ { name = 'find: empty negated character set', func = mw.ustring.find,
+ args = { "fóó", '[^]' },
+ expect = "malformed pattern (missing ']')"
+ },
{ name = 'match: (1)', func = mw.ustring.match,
args = { "bar fóo bar", 'f%a+' },
--
To view, visit https://gerrit.wikimedia.org/r/203975
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3310da55f655537c9082fc9039003f6b2d31eff4
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