Last modified: 2009-10-28 18:21:08 UTC
I take just the diff engine code to use on my app, then I got a minimal simple case where the diff engine fails. There is a try using the visual diff comparison algorithm, and below some code from my app that replicates the bug, you should be able to run the unit test case just adjusting the "requires" path. http://test.wikipedia.org/w/index.php?title=Sandbox&htmldiff=Visual+comparison&diff=68746&oldid=68745 ======================================== Code File <?php require_once('mediawiki/HTMLDiff.php'); require_once('mediawiki/Diff.php'); require_once('mediawiki/Nodes.php'); require_once('mediawiki/Xml.php'); require_once('mediawiki/Sanitizer.php'); /* <hack> */ /* I have no words to describe my love for global functions - and for people who rely on this kind of stuff, for sure */ function wfProfileIn($arg) {} function wfProfileOut($arg) {} function wfMsgExt($arg) {} function wfEmptyMsg($arg) {} /* </hack> */ class MyDelegate{ var $html = ''; function addHtml($html) { $this->html .= $html; } } class ContentDiff { function diff($old, $new) { $my_delegate = new MyDelegate(); $differ = new HTMLDiffer(new DelegatingContentHandler($my_delegate)); $differ->htmlDiff($old, $new); return $my_delegate->html; } } ?> ======================================== Test File <?php require_once 'PHPUnit/Framework.php'; require_once 'php/ContentDiff.php'; class ContentDiffTest extends PHPUnit_Framework_TestCase { public function test_scaring_bug() { $diff = new ContentDiff(); $html1 = "<p>teste</p><p><b>I came from the pampas</b></p>"; $html2 = "<p>teste</p><p><b>And Im a jedi!</b></p>"; $expected = "<p>teste</p>"; $expected .= "<p><b>"; $expected .= '<span class="diff-html-removed" id="removed-htmldiff-0">I came from the pampas</span>'; $expected .= '<span class="diff-html-added" id="added-htmldiff-0">And Im a jedi!</span>'; $expected .= "</b></p>"; $this->assertEquals($expected, $diff->diff($html1, $html2)); } } ?> =========================================== Got string <p>teste<b><span class="diff-html-removed" id="removed-htmldiff-0">I came from the pampas</span></b></p><p><b><span class="diff-html-added" id="added-htmldiff-0">And Im a jedi!</span></b></p>
HTMLDiff is very experimental and is disabled by default, I wouldn't recommend using it for anything.
Removed by bug 19859 and r58267.