mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX Fixed tag stacking in Diff.php thirdparty lib (AIR-71)
This commit is contained in:
parent
03db2894db
commit
3a5b3af7c6
@ -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
56
tests/core/DiffTest.php
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user