diff --git a/core/lib/Drupal/Component/Diff/Engine/DiffEngine.php b/core/lib/Drupal/Component/Diff/Engine/DiffEngine.php index c32017e300fe88829cdd6f084f2facf7e1aa6ff4..27b0f325724b09ba31deb109af71a2086c0db250 100644 --- a/core/lib/Drupal/Component/Diff/Engine/DiffEngine.php +++ b/core/lib/Drupal/Component/Diff/Engine/DiffEngine.php @@ -201,8 +201,9 @@ protected function _diag($xoff, $xlim, $yoff, $ylim, $nchunks) { continue; } $matches = $ymatches[$line]; + $found_empty = FALSE; foreach ($matches as $y) { - if (!isset($found_empty)) { + if (!$found_empty) { if (empty($this->in_seq[$y])) { $k = $this->_lcs_pos($y); $this::USE_ASSERTS && assert($k > 0); diff --git a/core/tests/Drupal/Tests/Component/Diff/Engine/DiffEngineTest.php b/core/tests/Drupal/Tests/Component/Diff/Engine/DiffEngineTest.php index 69f92daec9c79932f224b993f7e824a957839492..1714e663be55a4499d5c12f407b8d01c34c61719 100644 --- a/core/tests/Drupal/Tests/Component/Diff/Engine/DiffEngineTest.php +++ b/core/tests/Drupal/Tests/Component/Diff/Engine/DiffEngineTest.php @@ -86,4 +86,21 @@ public function testDiff($expected, $from, $to) { } } + /** + * Tests that two files can be successfully diffed. + * + * @covers ::diff + */ + public function testDiffInfiniteLoop() { + $from = explode("\n", file_get_contents(__DIR__ . '/fixtures/file1.txt')); + $to = explode("\n", file_get_contents(__DIR__ . '/fixtures/file2.txt')); + $diff_engine = new DiffEngine(); + $diff = $diff_engine->diff($from, $to); + $this->assertCount(4, $diff); + $this->assertEquals($diff[0], new DiffOpDelete([' - image.style.max_650x650'])); + $this->assertEquals($diff[1], new DiffOpCopy([' - image.style.max_325x325'])); + $this->assertEquals($diff[2], new DiffOpAdd([' - image.style.max_650x650', '_core:', ' default_config_hash: 3mjM9p-kQ8syzH7N8T0L9OnCJDSPvHAZoi3q6jcXJKM'])); + $this->assertEquals($diff[3], new DiffOpCopy(['fallback_image_style: max_325x325', ''])); + } + } diff --git a/core/tests/Drupal/Tests/Component/Diff/Engine/fixtures/file1.txt b/core/tests/Drupal/Tests/Component/Diff/Engine/fixtures/file1.txt new file mode 100644 index 0000000000000000000000000000000000000000..e50f1e8091d04db859786155add7114abaadfa21 --- /dev/null +++ b/core/tests/Drupal/Tests/Component/Diff/Engine/fixtures/file1.txt @@ -0,0 +1,3 @@ + - image.style.max_650x650 + - image.style.max_325x325 +fallback_image_style: max_325x325 diff --git a/core/tests/Drupal/Tests/Component/Diff/Engine/fixtures/file2.txt b/core/tests/Drupal/Tests/Component/Diff/Engine/fixtures/file2.txt new file mode 100644 index 0000000000000000000000000000000000000000..81a03582310bb3ad5e04ff4a74b91ea7aeec8f9c --- /dev/null +++ b/core/tests/Drupal/Tests/Component/Diff/Engine/fixtures/file2.txt @@ -0,0 +1,5 @@ + - image.style.max_325x325 + - image.style.max_650x650 +_core: + default_config_hash: 3mjM9p-kQ8syzH7N8T0L9OnCJDSPvHAZoi3q6jcXJKM +fallback_image_style: max_325x325