From 03db2894db50b851e5c29b7a66596b8977c8c657 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 9 Sep 2011 16:39:05 +0200 Subject: [PATCH] ENHANCEMENT Optional HTML escaping in Diff::compareHTML() (tested implicitly in DataDifferencerTest for sapphire) (AIR-56) --- core/Diff.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/core/Diff.php b/core/Diff.php index 5da7731ed..8157b7946 100644 --- a/core/Diff.php +++ b/core/Diff.php @@ -696,11 +696,17 @@ class Diff return $content; } - static function compareHTML($from, $to) { + /** + * @param String + * @param String + * @param Boolean + * @return String + */ + static function compareHTML($from, $to, $escape = false) { // First split up the content into words and tags $set1 = self::getHTMLChunks($from); $set2 = self::getHTMLChunks($to); - + // Diff that $diff = new Diff($set1, $set2); @@ -758,22 +764,25 @@ class Diff $diff = new Diff($rechunked[1], $rechunked[2]); $content = ''; foreach($diff->edits as $edit) { + $orig = ($escape) ? Convert::raw2xml($edit->orig) : $edit->orig; + $final = ($escape) ? Convert::raw2xml($edit->final) : $edit->final; + switch($edit->type) { case 'copy': - $content .= " " . implode(" ", $edit->orig) . " "; + $content .= " " . implode(" ", $orig) . " "; break; case 'change': - $content .= " " . implode(" ", $edit->final) . " "; - $content .= " " . implode(" ", $edit->orig) . " "; + $content .= " " . implode(" ", $final) . " "; + $content .= " " . implode(" ", $orig) . " "; break; case 'add': - $content .= " " . implode(" ", $edit->final) . " "; + $content .= " " . implode(" ", $final) . " "; break; case 'delete': - $content .= " " . implode(" ", $edit->orig) . " "; + $content .= " " . implode(" ", $orig) . " "; break; } }