ezyang / htmlpurifier

Standards compliant HTML filter written in PHP
http://htmlpurifier.org
GNU Lesser General Public License v2.1
3.09k stars 331 forks source link

PHP 7 weird output #191

Open reneappeldoorn opened 6 years ago

reneappeldoorn commented 6 years ago

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.

TheNewSound commented 6 years ago

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

ezyang commented 6 years ago

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?

reneappeldoorn commented 6 years ago

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...

ezyang commented 6 years ago

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.)

reneappeldoorn commented 6 years ago

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...