mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-27 07:20:08 +00:00
Force full evaluation of filter in FilterEvaluator->getUsedVars()
In some cases, evaluation short-circuits when getting a list of used variables resulting in an incomplete array of variables. This subsequently causes issues when using those arrays for validation checks (eg. if protected variables are used). - Force full evaluation by setting `mAllowShort` to false Bug: T364485 Change-Id: Idf2112d9ebf63846cde3ce9b8a8ade0ed909505d
This commit is contained in:
parent
25e1b8f8eb
commit
f5d7b68908
|
@ -454,7 +454,13 @@ class FilterEvaluator {
|
|||
*/
|
||||
public function getUsedVars( $filter ) {
|
||||
$this->resetState();
|
||||
$this->evaluateExpression( $filter );
|
||||
$cachedAllowShort = $this->mAllowShort;
|
||||
try {
|
||||
$this->mAllowShort = false;
|
||||
$this->evaluateExpression( $filter );
|
||||
} finally {
|
||||
$this->mAllowShort = $cachedAllowShort;
|
||||
}
|
||||
return array_unique( $this->usedVars );
|
||||
}
|
||||
|
||||
|
|
|
@ -1170,7 +1170,13 @@ class ParserTest extends ParserTestCase {
|
|||
$parser = $this->getParser();
|
||||
/** @var FilterEvaluator $wrapper */
|
||||
$wrapper = TestingAccessWrapper::newFromObject( $parser );
|
||||
$this->assertSame( [ 'user_name' ], $wrapper->getUsedVars( 'ip_in_range( user_name, "1.2.3.4" )' ) );
|
||||
$this->assertSame( [ 'user_name' ], $wrapper->getUsedVars( 'ip_in_range( USER_NAME, "1.2.3.4" )' ) );
|
||||
$this->assertSame(
|
||||
[ 'action', 'user_name' ],
|
||||
$wrapper->getUsedVars( 'action = "edit" & ip_in_range( user_name, "1.2.3.4" )' )
|
||||
);
|
||||
$this->assertSame(
|
||||
[ 'action', 'user_name' ],
|
||||
$wrapper->getUsedVars( 'action = "edit" & ip_in_range( USER_NAME, "1.2.3.4" )' )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue