php-htmldiff icon indicating copy to clipboard operation
php-htmldiff copied to clipboard

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

Open badams opened this issue 6 years ago • 1 comments

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)

badams avatar Dec 16 '18 20:12 badams

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

themiddlehalf avatar Aug 13 '21 18:08 themiddlehalf