BUGFIX Fixed tag stacking in Diff.php thirdparty lib (AIR-71)

This commit is contained in:
Ingo Schommer 2011-09-12 17:50:02 +02:00
parent 03db2894db
commit 3a5b3af7c6
2 changed files with 57 additions and 1 deletions

View File

@ -749,7 +749,7 @@ class Diff
if($tagStack[$listName]) $rechunked[$listName][sizeof($rechunked[$listName])-1] .= ' ' . $item;
else $rechunked[$listName][] = $item;
if($lookForTag && isset($item[0]) && $item[0] == "<" && substr($item,0,2) != "</") {
if($lookForTag && !$tagStack[$listName] && isset($item[0]) && $item[0] == "<" && substr($item,0,2) != "</") {
$tagStack[$listName] = 1;
} else if($tagStack[$listName]) {
if(substr($item,0,2) == "</") $tagStack[$listName]--;

56
tests/core/DiffTest.php Normal file
View File

@ -0,0 +1,56 @@
<?php
/**
* @package cms
* @subpackage tests
*/
class DiffTest extends SapphireTest {
/**
* @see https://groups.google.com/forum/#!topic/silverstripe-dev/yHcluCvuszo
*/
function testTableDiff() {
if(!class_exists('DOMDocument')) {
$this->markTestSkipped('"DOMDocument" required');
return;
}
$from = "<table>
<tbody>
<tr class=\"blah\">
<td colspan=\"2\">Row 1</td>
</tr>
<tr class=\"foo\">
<td>Row 2</td>
<td>Row 2</td>
</tr>
<tr>
<td>Row 3</td>
<td>Row 3</td>
</tr>
</tbody>
</table>";
$to = "<table class=\"new-class\">
<tbody>
<tr class=\"blah\">
<td colspan=\"2\">Row 1</td>
</tr>
<tr class=\"foo\">
<td>Row 2</td>
<td>Row 2</td>
</tr>
</tbody>
</table>";
$expected = "<ins>" . $to . "</ins>" . "<del>" . $from . "</del>";
$compare = Diff::compareHTML($from, $to);
// Very hard to debug this way, wouldn't need to do this if PHP had an *actual* DOM parsing lib,
// and not just the poor excuse that is DOMDocument
$compare = preg_replace('/[\s\t\n\r]*/', '', $compare);
$expected = preg_replace('/[\s\t\n\r]*/', '', $expected);
$this->assertEquals($compare, $expected);
}
}