mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #8111 from open-sausages/pulls/4/7.2-is-just-out-of-each
BUGFIX: Refactor difflib to not use each()
This commit is contained in:
commit
0bec6e07dc
@ -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 = "/^ *<del>$sentenceOne<\/del> *$sentenceTwo *<ins>$sentenceOne<\/ins> *$/";
|
||||
$actual = Diff::compareHTML($from, $to);
|
||||
|
||||
$this->assertRegExp($expected, $actual);
|
||||
}
|
||||
}
|
||||
|
7
thirdparty/difflib/difflib.php
vendored
7
thirdparty/difflib/difflib.php
vendored
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user