diff --git a/src/Differ.php b/src/Differ.php index f03206e..956bdea 100644 --- a/src/Differ.php +++ b/src/Differ.php @@ -483,7 +483,7 @@ private function finalize(): self $this->oldNoEolAtEofIdx = $this->getOld(-1) === [''] ? -1 : \count($this->old); $this->newNoEolAtEofIdx = $this->getNew(-1) === [''] ? -1 : \count($this->new); - $this->oldNewComparison = $this->old <=> $this->new; + $this->oldNewComparison = $this->old === $this->new ? 0 : ($this->old <=> $this->new ?: 1); $this->sequenceMatcher->setOptions($this->options->toSequenceMatcherOptions()); } diff --git a/tests/DifferTest.php b/tests/DifferTest.php index 985e201..4d1c46a 100644 --- a/tests/DifferTest.php +++ b/tests/DifferTest.php @@ -18,6 +18,19 @@ */ final class DifferTest extends TestCase { + /** + * Test that numeric strings that are equal numerically but not identical + * (e.g. "00" vs "0") are correctly detected as different. + * + * @covers \Jfcherng\Diff\Differ::getOldNewComparison + */ + public function testNumericStringComparisonIsStrict(): void + { + $differ = new Differ(['00'], ['0']); + + self::assertNotSame(0, $differ->getOldNewComparison()); + } + /** * Test the Differ::getGroupedOpcodes. *