htmlpurifier icon indicating copy to clipboard operation
htmlpurifier copied to clipboard

PHP 7 weird output

Open reneappeldoorn opened this issue 6 years ago • 5 comments

Using PHP 7 the output of René & Danny is René & Danny instead of the expected René & Danny. It's a specific character combination, you can test it using the following PHP code:

$msg = ['Testé &', 'Testéé &', 'Testé
& text &','Testéé & text
&','Testééé & text &'];
$pur_config = ['HTML.Allowed' =>
'br,p,strong,ol,ul,li,em,i,u,a[href]','HTML.TargetBlank' => true];
foreach($msg as $val){
 echo $val." - ".\Purify::clean($val, $pur_config)."<br />";
}

This behaviour is only on PHP 7, using the exact same code on PHP 5 the output will be as expected.

reneappeldoorn avatar Oct 04 '18 15:10 reneappeldoorn

can confirm this is happening on PHP7.1, on PHP5 everything works as expected.

TheNewSound avatar Oct 29 '18 09:10 TheNewSound

I can't reproduce.

ezyang@sabre:~/Dev/htmlpurifier$ php7.1 test.php
Testé &amp;
Testéé &amp;
Testé &amp; text &amp;
Testéé &amp; text &amp;
Testééé &amp; text &amp;
ezyang@sabre:~/Dev/htmlpurifier$ php test.php
Testé &amp;
Testéé &amp;
Testé &amp; text &amp;
Testéé &amp; text &amp;
Testééé &amp; text &amp;
ezyang@sabre:~/Dev/htmlpurifier$ cat test.php
<?php
include_once 'library/HTMLPurifier.auto.php';

$msg = ['Test&eacute; &amp;', 'Test&eacute;&eacute; &amp;', 'Test&eacute; &amp; text &amp;','Test&eacute;&eacute; &amp; text &amp;','Test&eacute;&eacute;&eacute; &amp; text &amp;'];
foreach($msg as $val){
    $purifier = new HTMLPurifier();
    echo $purifier->purify($val) . "\n";
}

Judging from the code sample, you're not using straight HTML Purifier. What library are you using?

ezyang avatar Nov 11 '18 22:11 ezyang

Thanks! Yes, we use the straight HTML Purifier. So I've gone one step further: I've been able to test it on PHP version 7.2.11 (output is fine!) and and PHP version 7.1.22 (output is wrong!) So it looks like it is a specific PHP 7.1.22 issue... are you able to test it on 7.1.22? Our production environment is currently on 7.1.22...

reneappeldoorn avatar Nov 12 '18 08:11 reneappeldoorn

That's very interesting. I test on 7.2.23, any reason you can't upgrade? :) (This is probably a PHP bug, but we can probably figure out a way to workaround it; it's not the first time we had to do this in HTML Purifier.)

ezyang avatar Nov 13 '18 05:11 ezyang

We can't upgrade to 7.2 yet, running an app that isn't yet compatible with 7.2. Would be nice to have a workaround, even though we're working on upgrading to to 7.2...

reneappeldoorn avatar Nov 13 '18 08:11 reneappeldoorn