diff --git a/tests/php/View/Parsers/DiffTest.php b/tests/php/View/Parsers/DiffTest.php index c55ee4dc3..e778ffa84 100644 --- a/tests/php/View/Parsers/DiffTest.php +++ b/tests/php/View/Parsers/DiffTest.php @@ -54,6 +54,27 @@ class DiffTest extends SapphireTest $compare = preg_replace('/[\s\t\n\r]*/', '', $compare); $expected = preg_replace('/[\s\t\n\r]*/', '', $expected); - $this->assertEquals($compare, $expected); + $this->assertEquals($expected, $compare); + } + + /** + * @see https://github.com/silverstripe/silverstripe-framework/issues/8053 + */ + public function testLegacyEachStatement() + { + $sentenceOne = + 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; + $sentenceTwo = + 'Nulla porttitor, ex quis commodo pharetra, diam dui efficitur justo, eu gravida elit eros vel libero.'; + + $from = "$sentenceOne $sentenceTwo"; + $to = "$sentenceTwo $sentenceOne"; + + // We're cheating our test a little bit here, because depending on what HTML cleaner you have, you'll get + // spaces added or not added around the tags. + $expected = "/^ *$sentenceOne<\/del> *$sentenceTwo *$sentenceOne<\/ins> *$/"; + $actual = Diff::compareHTML($from, $to); + + $this->assertRegExp($expected, $actual); } } diff --git a/thirdparty/difflib/difflib.php b/thirdparty/difflib/difflib.php index cf758ce90..16f012966 100644 --- a/thirdparty/difflib/difflib.php +++ b/thirdparty/difflib/difflib.php @@ -283,14 +283,17 @@ class DiffEngine continue; $matches = $ymatches[$line]; reset($matches); - while (list ($junk, $y) = each($matches)) + $pointer = 0; + foreach ($matches as $y) { + $pointer++; if (empty($this->in_seq[$y])) { $k = $this->lcs_pos($y); assert($k > 0); $ymids[$k] = $ymids[$k - 1]; break; } - while (list ($junk, $y) = each($matches)) { + } + foreach (array_slice($matches, $pointer) as $y) { if ($y > $this->seq[$k - 1]) { assert($y < $this->seq[$k]); // Optimization: this is a common case: