diff --git a/includes/parser/AbuseFilterParser.php b/includes/parser/AbuseFilterParser.php index 4169bcc5e..bf7cbaa23 100644 --- a/includes/parser/AbuseFilterParser.php +++ b/includes/parser/AbuseFilterParser.php @@ -159,12 +159,6 @@ class AbuseFilterParser { * @throws AFPUserVisibleException */ protected function skipOverBraces() { - if ( !( $this->mCur->type == AFPToken::TBRACE && $this->mCur->value == '(' ) || - !$this->mShortCircuit - ) { - return; - } - $braces = 1; while ( $this->mCur->type != AFPToken::TNONE && $braces > 0 ) { $this->move(); @@ -215,19 +209,6 @@ class AbuseFilterParser { return $result; } - /** - * @param string $a - * @param string $b - * @return int - */ - public static function lengthCompare( $a, $b ) { - if ( strlen( $a ) == strlen( $b ) ) { - return 0; - } - - return ( strlen( $a ) < strlen( $b ) ) ? -1 : 1; - } - /* Levels */ /** @@ -1346,10 +1327,6 @@ class AbuseFilterParser { protected static function equalsToAny( $string, $values ) { $string = $string->toString(); - if ( $string === '' ) { - return false; - } - foreach ( $values as $needle ) { $needle = $needle->toString(); diff --git a/tests/parserTests/atombraces.r b/tests/parserTests/atombraces.r new file mode 100644 index 000000000..f4efce9f5 --- /dev/null +++ b/tests/parserTests/atombraces.r @@ -0,0 +1 @@ +NOT MATCH diff --git a/tests/parserTests/atombraces.t b/tests/parserTests/atombraces.t new file mode 100644 index 000000000..5bb501903 --- /dev/null +++ b/tests/parserTests/atombraces.t @@ -0,0 +1 @@ +( ) diff --git a/tests/parserTests/containsfunction.r b/tests/parserTests/containsfunction.r new file mode 100644 index 000000000..f629599c3 --- /dev/null +++ b/tests/parserTests/containsfunction.r @@ -0,0 +1 @@ +MATCH \ No newline at end of file diff --git a/tests/parserTests/containsfunction.t b/tests/parserTests/containsfunction.t new file mode 100644 index 000000000..418c9e2c3 --- /dev/null +++ b/tests/parserTests/containsfunction.t @@ -0,0 +1,2 @@ +contains_any( "", "a") === false & +contains_any( "a", "", "a") === true \ No newline at end of file diff --git a/tests/parserTests/count.t b/tests/parserTests/count.t index 5733b0b2f..cc9e719ff 100644 --- a/tests/parserTests/count.t +++ b/tests/parserTests/count.t @@ -1,6 +1,8 @@ -count("a,b,c,d") = 4 & -count(",", "a,b,c,d") = 3 & -count("", "abcd") = 0 & -count("a", "abab") = 2 & -count("ab", "abab") = 2 & -count("aa", "aaaaa") = 2 +count("a,b,c,d") === 4 & +count(",", "a,b,c,d") === 3 & +count("", "abcd") === 0 & +count("a", "abab") === 2 & +count("ab", "abab") === 2 & +count("aa", "aaaaa") === 2 & +count( [ "a", "b", "c" ] ) === 3 & +count( [] ) === 0 diff --git a/tests/parserTests/equals-to-any.t b/tests/parserTests/equals-to-any.t index c812471c4..e10220ca7 100644 --- a/tests/parserTests/equals-to-any.t +++ b/tests/parserTests/equals-to-any.t @@ -1 +1,4 @@ -equals_to_any("foo", "bar", "foo", "pizza") & equals_to_any(15, 3, 77, 18, 15) \ No newline at end of file +equals_to_any( "foo", "bar", "foo", "pizza" ) & +equals_to_any( 15, 3, 77, 18, 15 ) & +equals_to_any( "", 3, 77, 18, 15, "duh" ) === false & +equals_to_any( "", 3, 77, 18, 15, "duh", "" ) \ No newline at end of file diff --git a/tests/parserTests/ifthen.t b/tests/parserTests/ifthen.t index 160d1ab80..c22a39470 100644 --- a/tests/parserTests/ifthen.t +++ b/tests/parserTests/ifthen.t @@ -1 +1,2 @@ -(if 1 then 2 else 3 end) == 2 +(if 1 then 2 else 3 end) === 2 & +(if false then 2 else 3 end) === 3 diff --git a/tests/parserTests/lazyboolinvert.r b/tests/parserTests/lazyboolinvert.r new file mode 100644 index 000000000..4736e0800 --- /dev/null +++ b/tests/parserTests/lazyboolinvert.r @@ -0,0 +1 @@ +MATCH diff --git a/tests/parserTests/lazyboolinvert.t b/tests/parserTests/lazyboolinvert.t new file mode 100644 index 000000000..71f5f2132 --- /dev/null +++ b/tests/parserTests/lazyboolinvert.t @@ -0,0 +1 @@ +1 === 1 | !true diff --git a/tests/parserTests/lazyfunction.r b/tests/parserTests/lazyfunction.r new file mode 100644 index 000000000..4736e0800 --- /dev/null +++ b/tests/parserTests/lazyfunction.r @@ -0,0 +1 @@ +MATCH diff --git a/tests/parserTests/lazyfunction.t b/tests/parserTests/lazyfunction.t new file mode 100644 index 000000000..4c77b374f --- /dev/null +++ b/tests/parserTests/lazyfunction.t @@ -0,0 +1 @@ +1 === 1 | contains_any( "a", "b") diff --git a/tests/parserTests/lazykeyword.r b/tests/parserTests/lazykeyword.r new file mode 100644 index 000000000..4736e0800 --- /dev/null +++ b/tests/parserTests/lazykeyword.r @@ -0,0 +1 @@ +MATCH diff --git a/tests/parserTests/lazykeyword.t b/tests/parserTests/lazykeyword.t new file mode 100644 index 000000000..da680aef1 --- /dev/null +++ b/tests/parserTests/lazykeyword.t @@ -0,0 +1 @@ +1 === 1 | "a" like "b" diff --git a/tests/parserTests/lazypow.r b/tests/parserTests/lazypow.r new file mode 100644 index 000000000..4736e0800 --- /dev/null +++ b/tests/parserTests/lazypow.r @@ -0,0 +1 @@ +MATCH diff --git a/tests/parserTests/lazypow.t b/tests/parserTests/lazypow.t new file mode 100644 index 000000000..8b650e270 --- /dev/null +++ b/tests/parserTests/lazypow.t @@ -0,0 +1 @@ +1 === 1 | 2**3 === 8 diff --git a/tests/parserTests/lazysum.r b/tests/parserTests/lazysum.r new file mode 100644 index 000000000..4736e0800 --- /dev/null +++ b/tests/parserTests/lazysum.r @@ -0,0 +1 @@ +MATCH diff --git a/tests/parserTests/lazysum.t b/tests/parserTests/lazysum.t new file mode 100644 index 000000000..9fedb3f3c --- /dev/null +++ b/tests/parserTests/lazysum.t @@ -0,0 +1 @@ +1 === 1 | 2 + 3 === 5 diff --git a/tests/parserTests/lazyunarys.r b/tests/parserTests/lazyunarys.r new file mode 100644 index 000000000..4736e0800 --- /dev/null +++ b/tests/parserTests/lazyunarys.r @@ -0,0 +1 @@ +MATCH diff --git a/tests/parserTests/lazyunarys.t b/tests/parserTests/lazyunarys.t new file mode 100644 index 000000000..51a1ce3e1 --- /dev/null +++ b/tests/parserTests/lazyunarys.t @@ -0,0 +1 @@ +1 === 1 | -4 !== 4 diff --git a/tests/parserTests/multipleskipbraces.r b/tests/parserTests/multipleskipbraces.r new file mode 100644 index 000000000..4736e0800 --- /dev/null +++ b/tests/parserTests/multipleskipbraces.r @@ -0,0 +1 @@ +MATCH diff --git a/tests/parserTests/multipleskipbraces.t b/tests/parserTests/multipleskipbraces.t new file mode 100644 index 000000000..ea8def7f5 --- /dev/null +++ b/tests/parserTests/multipleskipbraces.t @@ -0,0 +1 @@ +1 === 1 | ( ( ( 3 === 2 ) ) ) diff --git a/tests/parserTests/rcount.r b/tests/parserTests/rcount.r new file mode 100644 index 000000000..4736e0800 --- /dev/null +++ b/tests/parserTests/rcount.r @@ -0,0 +1 @@ +MATCH diff --git a/tests/parserTests/rcount.t b/tests/parserTests/rcount.t new file mode 100644 index 000000000..a514dad5f --- /dev/null +++ b/tests/parserTests/rcount.t @@ -0,0 +1,3 @@ +rcount("a,b,c,d") = 4 & +rcount(".", "abcd") = 4 + diff --git a/tests/parserTests/rmwhitespace.r b/tests/parserTests/rmwhitespace.r new file mode 100644 index 000000000..4736e0800 --- /dev/null +++ b/tests/parserTests/rmwhitespace.r @@ -0,0 +1 @@ +MATCH diff --git a/tests/parserTests/rmwhitespace.t b/tests/parserTests/rmwhitespace.t new file mode 100644 index 000000000..d6da2114e --- /dev/null +++ b/tests/parserTests/rmwhitespace.t @@ -0,0 +1,2 @@ +rmwhitespace( "foobar" ) === "foobar" & +rmwhitespace( "foo bar bar foo" ) === "foobarbarfoo" diff --git a/tests/parserTests/specialratio.t b/tests/parserTests/specialratio.t index c4a3565a7..5a1380a89 100644 --- a/tests/parserTests/specialratio.t +++ b/tests/parserTests/specialratio.t @@ -1 +1,2 @@ -specialratio("foó;") = 0.25 +specialratio("foó;") === 0.25 & +specialratio("") === 0.0 diff --git a/tests/parserTests/strpos.r b/tests/parserTests/strpos.r new file mode 100644 index 000000000..4736e0800 --- /dev/null +++ b/tests/parserTests/strpos.r @@ -0,0 +1 @@ +MATCH diff --git a/tests/parserTests/strpos.t b/tests/parserTests/strpos.t new file mode 100644 index 000000000..65312318f --- /dev/null +++ b/tests/parserTests/strpos.t @@ -0,0 +1,4 @@ +strpos( "foobarfoo", "foo" ) === 0 & +strpos( "foobarfoo", "" ) === -1 & +strpos( "foobarfoo", "foo", 1 ) === 6 & +strpos( "foobarfoo", "lol" ) === -1 diff --git a/tests/parserTests/substr.r b/tests/parserTests/substr.r new file mode 100644 index 000000000..4736e0800 --- /dev/null +++ b/tests/parserTests/substr.r @@ -0,0 +1 @@ +MATCH diff --git a/tests/parserTests/substr.t b/tests/parserTests/substr.t new file mode 100644 index 000000000..b1135066f --- /dev/null +++ b/tests/parserTests/substr.t @@ -0,0 +1,2 @@ +substr( "foobar", 0, 3 ) === "foo" & +substr( "barfoo", 4 ) === "oo" diff --git a/tests/phpunit/AbuseFilterParserTest.php b/tests/phpunit/AbuseFilterParserTest.php index a168f1361..31045b9fa 100644 --- a/tests/phpunit/AbuseFilterParserTest.php +++ b/tests/phpunit/AbuseFilterParserTest.php @@ -52,8 +52,9 @@ class AbuseFilterParserTest extends MediaWikiTestCase { static $parsers = null; if ( !$parsers ) { $parsers = [ - new AbuseFilterParser(), - new AbuseFilterCachingParser() + new AbuseFilterParser() + // @ToDo: Here we should also instantiate an AbuseFilterCachingParser as we'll have + // fixed its problems (T156095). Right now it may break otherwise working tests (see T201193) ]; } return $parsers; @@ -147,26 +148,6 @@ class AbuseFilterParserTest extends MediaWikiTestCase { ]; } - /** - * get_matches should throw an exception with an invalid number of arguments. - * @expectedException AFPUserVisibleException - * @covers AbuseFilterParser::funcGetMatches - */ - public function testGetMatchesInvalidArgs() { - $parser = self::getParser(); - $parser->parse( "get_matches('')" ); - } - - /** - * get_matches should throw an exception when given an invalid regular expression. - * @expectedException AFPUserVisibleException - * @covers AbuseFilterParser::funcGetMatches - */ - public function testGetMatchesInvalidRegex() { - $parser = self::getParser(); - $parser->parse( "get_matches('this (should fail')" ); - } - /** * Ensure get_matches function captures returns expected output. * @param string $needle Regex to pass to get_matches. @@ -498,6 +479,7 @@ class AbuseFilterParserTest extends MediaWikiTestCase { * @param string $expr The expression to test * @param string $caller The function where the exception is thrown * @covers AbuseFilterParser::funcRCount + * @covers AbuseFilterParser::funcGetMatches * @dataProvider regexFailure */ public function testRegexFailureException( $expr, $caller ) { @@ -514,6 +496,7 @@ class AbuseFilterParserTest extends MediaWikiTestCase { public function regexFailure() { return [ [ "rcount('(','a')", 'funcRCount' ], + [ "get_matches('this (should fail', 'any haystack')", 'funcGetMatches' ], ]; }