Fix a bug in the return value of the CachingParser

This has always been wrong, and remained unnoticed. Also added a
typehint for added safety.

Change-Id: I8a3c31e7385283d95b4712d457784016239a0b3b
This commit is contained in:
Daimona Eaytoy 2019-08-20 20:54:19 +02:00
parent 7addec7b4a
commit fa76405ea7
3 changed files with 9 additions and 2 deletions

View file

@ -44,7 +44,7 @@ class AbuseFilterCachingParser extends AbuseFilterParser {
* @param string $code
* @return AFPData
*/
public function intEval( $code ) {
public function intEval( $code ) : AFPData {
static $cache = null;
if ( !$cache ) {
$cache = ObjectCache::getLocalServerInstance( 'hash' );
@ -285,6 +285,7 @@ class AbuseFilterCachingParser extends AbuseFilterParser {
}
$array = $this->mVariables->getVar( $varName );
$value = $this->evalNode( $value );
if ( $array->getType() !== AFPData::DUNDEFINED ) {
// If it's a DUNDEFINED, leave it as is
if ( $array->getType() !== AFPData::DARRAY ) {
@ -299,7 +300,7 @@ class AbuseFilterCachingParser extends AbuseFilterParser {
[ $offset, count( $array ) ] );
}
$array[$offset] = $this->evalNode( $value );
$array[$offset] = $value;
$this->setUserVariable( $varName, new AFPData( AFPData::DARRAY, $array ) );
}

View file

@ -0,0 +1,3 @@
/* CachingParser's intEval used to return AFPTreeNode for this */
var := [1];
var[0] := 2;

View file

@ -0,0 +1,3 @@
/* CachingParser's intEval used to return AFPTreeNode for this */
var := [1];
var[0] := str_replace('a','b','c');