From 47c9deec0ec20d4e5dffbc72020fae1d2f56f6b3 Mon Sep 17 00:00:00 2001 From: Adam Lundrigan Date: Tue, 27 Oct 2015 11:28:16 -0230 Subject: [PATCH 1/2] Failing test case to expose #41 --- test/ArrayUtilsTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/ArrayUtilsTest.php b/test/ArrayUtilsTest.php index 8127276fe..1d21cb694 100644 --- a/test/ArrayUtilsTest.php +++ b/test/ArrayUtilsTest.php @@ -542,4 +542,15 @@ public function testInvalidCallableRaiseInvalidArgumentException() { ArrayUtils::filter([], "INVALID"); } + + /** + * @see https://github.com/zendframework/zend-stdlib/issues/41 + */ + public function testInArrayFunctionCallShouldAlwaysBeStrictToPreventStringMatchingIssues() + { + $needle = '1.10'; + $haystack = ['1.1']; + + $this->assertFalse(ArrayUtils::inArray($needle, $haystack)); + } } From 57329bce656fa86220bd798bb929023ed37684f1 Mon Sep 17 00:00:00 2001 From: Adam Lundrigan Date: Tue, 27 Oct 2015 11:28:39 -0230 Subject: [PATCH 2/2] Underlying call to in_array in ArrayUtils::inArray should always be strict --- src/ArrayUtils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ArrayUtils.php b/src/ArrayUtils.php index 17e3ae3cd..69b97219a 100644 --- a/src/ArrayUtils.php +++ b/src/ArrayUtils.php @@ -199,7 +199,7 @@ public static function inArray($needle, array $haystack, $strict = false) } } } - return in_array($needle, $haystack, $strict); + return in_array($needle, $haystack, true); } /**