mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-23 21:53:35 +00:00
Merge "Simplify FilterEvaluator::getUsedVars using ::checkSyntax"
This commit is contained in:
commit
98eab47d9b
|
@ -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