diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index a5555f6d7a3..c9a31cc4d8a 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -7296,15 +7296,16 @@ function dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox = 0, $check = ' do { $oldstringtoclean = $out; + libxml_use_internal_errors(false); // Avoid to fill memory with xml errors + if (!empty($out) && !empty($conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML) && $check != 'restricthtmlallowunvalid') { try { $dom = new DOMDocument; // Add a trick to solve pb with text without parent tag - // like '

Foo

bar

' that wrongly ends up without the trick into '

Foo

bar

' - // like 'abc' that wrongly ends up without the tric into with '

abc

' + // like '

Foo

bar

' that wrongly ends up, without the trick, with '

Foo

bar

' + // like 'abc' that wrongly ends up, without the trick, with '

abc

' $out = '
'.$out.'
'; - - $dom->loadHTML($out, LIBXML_ERR_NONE|LIBXML_HTML_NOIMPLIED|LIBXML_HTML_NODEFDTD|LIBXML_NONET|LIBXML_NOWARNING|LIBXML_NOXMLDECL); + $dom->loadHTML($out, LIBXML_HTML_NODEFDTD|LIBXML_ERR_NONE|LIBXML_HTML_NOIMPLIED|LIBXML_NONET|LIBXML_NOWARNING|LIBXML_NOXMLDECL); $out = trim($dom->saveHTML()); // Remove the trick added to solve pb with text without parent tag diff --git a/test/phpunit/SecurityTest.php b/test/phpunit/SecurityTest.php index 4a0b65333ff..1138e06d3b2 100644 --- a/test/phpunit/SecurityTest.php +++ b/test/phpunit/SecurityTest.php @@ -390,6 +390,7 @@ class SecurityTest extends PHPUnit\Framework\TestCase $_POST["param13b"]='n n > < " XSS'; $_POST["param14"]="Text with ' encoded with the numeric html entity converted into text entity ' (like when submited by CKEditor)"; $_POST["param15"]=" src=>0xbeefed"; + //$_POST["param15b"]="Example HTML

This is a paragraph.