mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-11-27 17:50:06 +00:00
Make sure that lua stack trace is valid UTF-8.
This fixes a warning on php8.1 related to preg_match_all returning
null when given invalid UTF-8.
I made a separate patch to change the null into an exception Ic0c9083b
In a sense, this is a follow-up to ec103b6966
.
Bug: T319218
Change-Id: Ia17fc2fa428ec35bdbd242f1127fcdff501fb741
This commit is contained in:
parent
0f2585244c
commit
047200c11e
|
@ -81,7 +81,16 @@ class LuaSandboxInterpreter extends LuaInterpreter {
|
|||
protected function convertSandboxError( LuaSandboxError $e ) {
|
||||
$opts = [];
|
||||
if ( isset( $e->luaTrace ) ) {
|
||||
$opts['trace'] = $e->luaTrace;
|
||||
$trace = $e->luaTrace;
|
||||
foreach ( $trace as &$val ) {
|
||||
$val = array_map( static function ( $val ) {
|
||||
if ( is_string( $val ) ) {
|
||||
$val = Validator::cleanUp( $val );
|
||||
}
|
||||
return $val;
|
||||
}, $val );
|
||||
}
|
||||
$opts['trace'] = $trace;
|
||||
}
|
||||
$message = Validator::cleanUp( $e->getMessage() );
|
||||
if ( preg_match( '/^(.*?):(\d+): (.*)$/', $message, $m ) ) {
|
||||
|
|
|
@ -416,6 +416,14 @@ class LuaStandaloneInterpreter extends LuaInterpreter {
|
|||
$message['value'] = $m[3];
|
||||
}
|
||||
if ( isset( $message['trace'] ) ) {
|
||||
foreach ( $message['trace'] as &$val ) {
|
||||
$val = array_map( static function ( $val ) {
|
||||
if ( is_string( $val ) ) {
|
||||
$val = Validator::cleanUp( $val );
|
||||
}
|
||||
return $val;
|
||||
}, $val );
|
||||
}
|
||||
$opts['trace'] = array_values( $message['trace'] );
|
||||
}
|
||||
throw $this->engine->newLuaError( $message['value'], $opts );
|
||||
|
|
Loading…
Reference in a new issue