Skip to content
Snippets Groups Projects
Commit 0f34cdd4 authored by catch's avatar catch
Browse files

Issue #2936941 by alexpott: Diff can infinitely loop since #2885309

parent 14c499fc
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -201,8 +201,9 @@ protected function _diag($xoff, $xlim, $yoff, $ylim, $nchunks) { ...@@ -201,8 +201,9 @@ protected function _diag($xoff, $xlim, $yoff, $ylim, $nchunks) {
continue; continue;
} }
$matches = $ymatches[$line]; $matches = $ymatches[$line];
$found_empty = FALSE;
foreach ($matches as $y) { foreach ($matches as $y) {
if (!isset($found_empty)) { if (!$found_empty) {
if (empty($this->in_seq[$y])) { if (empty($this->in_seq[$y])) {
$k = $this->_lcs_pos($y); $k = $this->_lcs_pos($y);
$this::USE_ASSERTS && assert($k > 0); $this::USE_ASSERTS && assert($k > 0);
......
...@@ -86,4 +86,21 @@ public function testDiff($expected, $from, $to) { ...@@ -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', '']));
}
} }
- image.style.max_650x650
- image.style.max_325x325
fallback_image_style: max_325x325
- image.style.max_325x325
- image.style.max_650x650
_core:
default_config_hash: 3mjM9p-kQ8syzH7N8T0L9OnCJDSPvHAZoi3q6jcXJKM
fallback_image_style: max_325x325
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment