Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit 3a5b3af7c697235ace7ce5c66df074e9368199a2 1 parent 03db289
@chillu chillu authored
Showing with 57 additions and 1 deletion.
  1. +1 −1  core/Diff.php
  2. +56 −0 tests/core/DiffTest.php
View
2  core/Diff.php
@@ -749,7 +749,7 @@ static function compareHTML($from, $to, $escape = false) {
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]--;
View
56 tests/core/DiffTest.php
@@ -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);
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.