mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-09-24 10:49:52 +00:00
Merge "ustring: Handle empty charset like Lua does"
This commit is contained in:
commit
5a74dd4a50
|
@ -463,6 +463,10 @@ class Scribunto_LuaUstringLibrary extends Scribunto_LuaLibraryBase {
|
|||
$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" );
|
||||
}
|
||||
|
|
|
@ -567,6 +567,10 @@ local function find( s, cps, rawpat, pattern, init, noAnchor )
|
|||
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
|
||||
|
|
|
@ -429,6 +429,14 @@ return testframework.getTestProvider( {
|
|||
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+' },
|
||||
|
|
Loading…
Reference in a new issue