Skip to content

Commit

Permalink
BUGFIX Bypassing setters in DataDifferencer to avoid problems with in…
Browse files Browse the repository at this point in the history
…valid data (e.g. HTML fragment instead of valid classname in SiteTree->setClassname(). Better validation of constructor parameters (AIR-42)
  • Loading branch information
chillu committed Oct 7, 2011
1 parent 7403056 commit 8cc1b4c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions model/DataDifferencer.php
Expand Up @@ -42,8 +42,11 @@ class DataDifferencer extends ViewableData {
/**
* Construct a DataDifferencer to show the changes between $fromRecord and $toRecord.
* If $fromRecord is null, this will represent a "creation".
*
* @param DataObject (Optional)
* @param DataObject
*/
function __construct($fromRecord, $toRecord) {
function __construct($fromRecord, DataObject $toRecord) {
if(!$toRecord) user_error("DataDifferencer constructed without a toRecord", E_USER_WARNING);
$this->fromRecord = $fromRecord;
$this->toRecord = $toRecord;
Expand Down Expand Up @@ -77,9 +80,9 @@ function diffedData() {
if(in_array($field, $this->ignoredFields)) continue;

if(!$this->fromRecord) {
$diffed->$field = "<ins>" . $this->toRecord->$field . "</ins>";
$diffed->setField($field, "<ins>" . $this->toRecord->$field . "</ins>");
} else if($this->fromRecord->$field != $this->toRecord->$field) {
$diffed->$field = Diff::compareHTML($this->fromRecord->$field, $this->toRecord->$field);
$diffed->setField($field, Diff::compareHTML($this->fromRecord->$field, $this->toRecord->$field));
}
}

Expand Down

0 comments on commit 8cc1b4c

Please sign in to comment.