From a31f4e46af479fe611477efeea628f5d7f867ab5 Mon Sep 17 00:00:00 2001 From: proc Date: Sat, 27 Jun 2020 15:11:21 +0100 Subject: [PATCH] Strict type comparison Bug: T248806 Change-Id: I039ab7f103bb37052987b815412b71f70643a6d2 --- includes/parser/AbuseFilterParser.php | 6 +----- tests/parserTests/equals-to-any.t | 11 ++++++++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/includes/parser/AbuseFilterParser.php b/includes/parser/AbuseFilterParser.php index 06a361c06..fabd38090 100644 --- a/includes/parser/AbuseFilterParser.php +++ b/includes/parser/AbuseFilterParser.php @@ -1529,12 +1529,8 @@ class AbuseFilterParser extends AFPTransitionBase { * @return bool */ protected static function equalsToAny( $string, $values ) { - $string = $string->toString(); - foreach ( $values as $needle ) { - $needle = $needle->toString(); - - if ( $string === $needle ) { + if ( $string->equals( $needle, true ) ) { return true; } } diff --git a/tests/parserTests/equals-to-any.t b/tests/parserTests/equals-to-any.t index e10220ca7..c46462af9 100644 --- a/tests/parserTests/equals-to-any.t +++ b/tests/parserTests/equals-to-any.t @@ -1,4 +1,13 @@ 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 +equals_to_any( "", 3, 77, 18, 15, "duh", "" ) & +equals_to_any( true, 1, "true" ) === false & +equals_to_any( "1", 1, [ 1 ], true ) === false & +equals_to_any( [ 1, "1" ], 1, "1" ) === false & +equals_to_any( [ 1, 2, 3 ], [ 1, 2, 3 ] ) & +equals_to_any( [ 1, 2, 3 ], [ 3, 2, 1 ] ) === false & +equals_to_any( [ "foo", "bar" ], [ ] ) === false & +equals_to_any( [ "foo", "bar" ], [ "foo", "bar" ] ) & +equals_to_any( [], [] ) & +equals_to_any( [ 0 ], [] ) === false