Skip to content

Commit

Permalink
Fix weak comparison between '0' and false
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek authored and sebastianbergmann committed Sep 14, 2022
1 parent 1071dfc commit a6635b6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ScalarComparator.php
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions tests/ScalarComparatorTest.php
Expand Up @@ -46,6 +46,7 @@ public function acceptsSucceedsProvider()
['1', true],
[1, true],
[0, false],
['0', false],
[0.1, '0.1']
];
}
Expand Down Expand Up @@ -77,6 +78,7 @@ public function assertEqualsSucceedsProvider()
['1', true],
[1, true],
[0, false],
['0', false],
[0.1, '0.1'],
[false, null],
[false, false],
Expand Down

0 comments on commit a6635b6

Please sign in to comment.