From e36c48e3cb40e2a986a627fde07f3c2b8e1968bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sat, 21 May 2022 23:41:47 +0200 Subject: [PATCH] Fix weak comparison between `'0'` and false --- src/ScalarComparator.php | 2 +- tests/ScalarComparatorTest.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ScalarComparator.php b/src/ScalarComparator.php index e19df4d..02f3986 100644 --- a/src/ScalarComparator.php +++ b/src/ScalarComparator.php @@ -51,7 +51,7 @@ public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = f // always compare as strings to avoid strange behaviour // otherwise 0 == 'Foobar' - if (\is_string($expected) || \is_string($actual)) { + if ((\is_string($expected) && !\is_bool($actual)) || (\is_string($actual) && !\is_bool($expected))) { $expectedToCompare = (string) $expectedToCompare; $actualToCompare = (string) $actualToCompare; diff --git a/tests/ScalarComparatorTest.php b/tests/ScalarComparatorTest.php index 11feae2..4f29c2f 100644 --- a/tests/ScalarComparatorTest.php +++ b/tests/ScalarComparatorTest.php @@ -46,6 +46,7 @@ public function acceptsSucceedsProvider() ['1', true], [1, true], [0, false], + ['0', false], [0.1, '0.1'] ]; } @@ -77,6 +78,7 @@ public function assertEqualsSucceedsProvider() ['1', true], [1, true], [0, false], + ['0', false], [0.1, '0.1'], [false, null], [false, false],