mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT Optional HTML escaping in Diff::compareHTML() (tested implicitly in DataDifferencerTest for sapphire) (AIR-56)
This commit is contained in:
parent
72d5423ac5
commit
03db2894db
@ -696,7 +696,13 @@ 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);
|
||||
@ -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 .= " <ins>" . implode(" ", $edit->final) . "</ins> ";
|
||||
$content .= " <del>" . implode(" ", $edit->orig) . "</del> ";
|
||||
$content .= " <ins>" . implode(" ", $final) . "</ins> ";
|
||||
$content .= " <del>" . implode(" ", $orig) . "</del> ";
|
||||
break;
|
||||
|
||||
case 'add':
|
||||
$content .= " <ins>" . implode(" ", $edit->final) . "</ins> ";
|
||||
$content .= " <ins>" . implode(" ", $final) . "</ins> ";
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
$content .= " <del>" . implode(" ", $edit->orig) . "</del> ";
|
||||
$content .= " <del>" . implode(" ", $orig) . "</del> ";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user