caxy / php-htmldiff

A library for comparing two HTML files/snippets and highlighting the differences using simple HTML. Includes support for comparing complex lists and tables
http://php-htmldiff.caxy.com
GNU General Public License v2.0
202 stars 51 forks source link

Purifier Config settings not having affect across all classes (e.g. TableDiff) #78

Open badams opened 5 years ago

badams commented 5 years ago

Seems like the Purifier config is not being passed down to "nested diff instances"; When a document is being processed new HtmlDiff instances and instances of other classes such as TableDiff are created, if the user provides a HTMLPurifier_Config when creating the top level diff its not passed down to any subsequent instances that are created.

For example the following code should ensure the entire document is returned instead of just the body content.

$oldHtml = '<html><head><style>h1 {color: red}</style></head><body><h1>Hello World</h1><p>Testing</p></body></html>';
$newHtml = '<html><head><style>h1 {color: red}</style></head><body><h1>Hello Every Body!</h1><p>Testing</p></body></html>';
$diff = HtmlDiff::create($oldHtml, $newHtml);
$config =  \HTMLPurifier_Config::createDefault();
$config->set('Core.ConvertDocumentToFragment', false);
$diff->setHTMLPurifierConfig($config);
$diff->build();

results in the following:

<h1>Hello <del class="diffmod">World</del><ins class="diffmod">Every Body!</ins></h1><p>Testing</p>

When you would expect the html/head tags to be included in the output.

Stepping through this with xdebug you notice that the PurifierConfig value Core.ConvertDocumentToFragment is set to true (the default value)

themiddlehalf commented 3 years ago

I don't believe purifier will retain the html/head tags even if this setting is set to false. https://github.com/ezyang/htmlpurifier/issues/250