2
0
forked from Wavyzz/dolibarr

FIX dol_string_nohtmltag make 2 passes to clean html into html

attributes.
This commit is contained in:
Laurent Destailleur
2017-05-31 11:11:25 +02:00
parent 292571688b
commit 145cb628cd
2 changed files with 14 additions and 1 deletions

View File

@@ -4704,7 +4704,12 @@ function dol_string_nohtmltag($StringHtml,$removelinefeed=1,$pagecodeto='UTF-8')
$pattern = "/<[^<>]+>/";
$StringHtml = preg_replace('/<br[^>]*>/', "\n", $StringHtml);
$temp = dol_html_entity_decode($StringHtml,ENT_COMPAT,$pagecodeto);
$temp = preg_replace($pattern,"",$temp);
// Exemple of $temp: <a href="/myurl" title="<u>A title</u>">0000-021</a>
$temp = preg_replace($pattern,"",$temp); // pass 1
// $temp after pass 1: <a href="/myurl" title="A title">0000-021
$temp = preg_replace($pattern,"",$temp); // pass 2
// $temp after pass 2: 0000-021
// Supprime aussi les retours
if ($removelinefeed) $temp=str_replace(array("\r\n","\r","\n")," ",$temp);

View File

@@ -377,6 +377,14 @@ class FunctionsLibTest extends PHPUnit_Framework_TestCase
$after=dol_string_nohtmltag($text,1);
$this->assertEquals("A string Another string",$after,"test5");
$text='<a href="/myurl" title="<u>Afficher projet</u>">ABC</a>';
$after=dol_string_nohtmltag($text,1);
$this->assertEquals("ABC",$after,"test6");
$text='<a href="/myurl" title="&lt;u&gt;Afficher projet&lt;/u&gt;">DEF</a>';
$after=dol_string_nohtmltag($text,1);
$this->assertEquals("DEF",$after,"test7");
return true;
}