FIX html detection fails if only u tag is present

This commit is contained in:
Laurent Destailleur 2016-07-26 16:11:38 +02:00
parent 2866d60240
commit b615b52f47
2 changed files with 16 additions and 13 deletions

View File

@ -4548,7 +4548,7 @@ function dol_textishtml($msg,$option=0)
{
if (preg_match('/<html/i',$msg)) return true;
elseif (preg_match('/<body/i',$msg)) return true;
elseif (preg_match('/<(b|em|i)>/i',$msg)) return true;
elseif (preg_match('/<(b|em|i|u)>/i',$msg)) return true;
elseif (preg_match('/<(br|div|font|li|p|span|strong|table)>/i',$msg)) return true;
elseif (preg_match('/<(br|div|font|li|p|span|strong|table)\s+[^<>\/]*>/i',$msg)) return true;
elseif (preg_match('/<(br|div|font|li|p|span|strong|table)\s+[^<>\/]*\/>/i',$msg)) return true;

View File

@ -206,40 +206,43 @@ class FunctionsLibTest extends PHPUnit_Framework_TestCase
// True
$input='<html>xxx</html>';
$after=dol_textishtml($input);
$this->assertTrue($after);
$this->assertTrue($after, 'Test with html tag');
$input='<body>xxx</body>';
$after=dol_textishtml($input);
$this->assertTrue($after);
$this->assertTrue($after, 'Test with body tag');
$input='xxx <b>yyy</b> zzz';
$after=dol_textishtml($input);
$this->assertTrue($after);
$this->assertTrue($after, 'Test with b tag');
$input='xxx <u>yyy</u> zzz';
$after=dol_textishtml($input);
$this->assertTrue($after, 'Test with u tag');
$input='text with <div>some div</div>';
$after=dol_textishtml($input);
$this->assertTrue($after);
$this->assertTrue($after, 'Test with div tag');
$input='text with HTML &nbsp; entities';
$after=dol_textishtml($input);
$this->assertTrue($after);
$this->assertTrue($after, 'Test with entities tag');
$input='xxx<br>';
$after=dol_textishtml($input);
$this->assertTrue($after);
$this->assertTrue($after, 'Test with entities br');
$input='xxx<br >';
$after=dol_textishtml($input);
$this->assertTrue($after);
$this->assertTrue($after, 'Test with entities br');
$input='xxx<br style="eee">';
$after=dol_textishtml($input);
$this->assertTrue($after);
$this->assertTrue($after, 'Test with entities br and attributes');
$input='xxx<br style="eee" >';
$after=dol_textishtml($input);
$this->assertTrue($after);
$this->assertTrue($after, 'Test with entities br and attributes bis');
$input='<h2>abc</h2>';
$after=dol_textishtml($input);
$this->assertTrue($after);
$this->assertTrue($after, 'Test with entities h2');
$input='<img id="abc" src="https://xxx.com/aaa/image.png" />';
$after=dol_textishtml($input);
$this->assertTrue($after,'Failure on test of img tag');
$this->assertTrue($after, 'Test with img tag');
$input='<a class="azerty" href="https://xxx.com/aaa/image.png" />';
$after=dol_textishtml($input);
$this->assertTrue($after,'Failure on test of a tag');
$this->assertTrue($after, 'Test with a tag');
// False
$input='xxx < br>';