mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-23 13:46:48 +00:00
Simplify FilterEvaluator::getUsedVars using ::checkSyntax
Alternative approach to fixing the regression proposed by Daimona in I78d3a2cd7bada962d7ef9b0f2c39d898bf8987ce. Bug: T368203 Change-Id: I637367c3b3850f7988d890379fef7f4753159953
This commit is contained in:
parent
6b26f27927
commit
bf180e0490
|
@ -450,17 +450,10 @@ class FilterEvaluator {
|
|||
* and saved to self::usedVars to be returned to the caller in this function.
|
||||
*
|
||||
* @param string $filter
|
||||
* @return array
|
||||
* @return string[]
|
||||
*/
|
||||
public function getUsedVars( string $filter ): array {
|
||||
$this->resetState();
|
||||
$cachedAllowShort = $this->mAllowShort;
|
||||
try {
|
||||
$this->mAllowShort = false;
|
||||
$this->evaluateExpression( $filter );
|
||||
} finally {
|
||||
$this->mAllowShort = $cachedAllowShort;
|
||||
}
|
||||
$this->checkSyntax( $filter );
|
||||
return array_unique( $this->usedVars );
|
||||
}
|
||||
|
||||
|
|
|
@ -1163,20 +1163,19 @@ class ParserTest extends ParserTestCase {
|
|||
$this->assertSame( $vars, $wrapper->mVariables );
|
||||
}
|
||||
|
||||
public static function provideGetUsedVars() {
|
||||
yield [ [ 'action', 'user_name' ], 'action = "edit" & ip_in_range( user_name, "1.2.3.4" )' ];
|
||||
yield [ [ 'action', 'user_name' ], 'action = "edit" & ip_in_range( USER_NAME, "1.2.3.4" )' ];
|
||||
yield [ [ 'added_lines' ], "added_lines[0] !== ''" ];
|
||||
yield [ [ 'old_size', 'new_size' ], 'old_size > 0 & new_size / old_size < 0.5' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \MediaWiki\Extension\AbuseFilter\Parser\FilterEvaluator
|
||||
* @dataProvider provideGetUsedVars
|
||||
*/
|
||||
public function testGetUsedVars() {
|
||||
public function testGetUsedVars( $expected, $conditions ) {
|
||||
$parser = $this->getParser();
|
||||
/** @var FilterEvaluator $wrapper */
|
||||
$wrapper = TestingAccessWrapper::newFromObject( $parser );
|
||||
$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" )' )
|
||||
);
|
||||
$this->assertSame( $expected, $parser->getUsedVars( $conditions ) );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue