diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index c3889a41456..9016f81ce34 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -3414,13 +3414,13 @@ function picto_required()
* Clean a string from all HTML tags and entities
*
* @param string $StringHtml String to clean
- * @param string $removelinefeed Replace also all lines feeds by a space
+ * @param string $removelinefeed Replace also all lines feeds by a space, otherwise only last one are removed
* @param string $pagecodeto Encoding of input/output string
* @return string String cleaned
*/
function dol_string_nohtmltag($StringHtml,$removelinefeed=1,$pagecodeto='UTF-8')
{
- $pattern = "/<[^>]+>/";
+ $pattern = "/<[^<>]+>/";
$temp = dol_html_entity_decode($StringHtml,ENT_COMPAT,$pagecodeto);
$temp = preg_replace($pattern,"",$temp);
@@ -3486,7 +3486,6 @@ function dol_htmlentitiesbr($stringtoencode,$nl2brmode=0,$pagecodefrom='UTF-8')
$newstring=strtr($newstring,array('&'=>'__and__','<'=>'__lt__','>'=>'__gt__','"'=>'__dquot__'));
$newstring=dol_htmlentities($newstring,ENT_COMPAT,$pagecodefrom); // Make entity encoding
$newstring=strtr($newstring,array('__and__'=>'&','__lt__'=>'<','__gt__'=>'>','__dquot__'=>'"'));
- //$newstring=strtr($newstring,array('__li__'=>"
\n")); // Restore \n
}
else
{
@@ -3530,7 +3529,7 @@ function dol_htmlcleanlastbr($stringtodecode)
* Replace html_entity_decode functions to manage errors
*
* @param string $a Operand a
- * @param string $b Operand b
+ * @param string $b Operand b (ENT_QUOTES=convert simple and double quotes)
* @param string $c Operand c
* @return string String decoded
*/
@@ -3670,17 +3669,10 @@ function dol_textishtml($msg,$option=0)
{
if (preg_match('//i',$msg)) return true;
- elseif (preg_match('/
/i',$msg)) return true;
- elseif (preg_match('//i',$msg)) return true;
- elseif (preg_match('//i',$msg)) return true;
+ elseif (preg_match('/<(br|div|font|img|li|span|strong|table)>/i',$msg)) return true;
+ elseif (preg_match('/<(br|div|font|img|li|span|strong|table)\s+[^<>\/]*>/i',$msg)) return true;
+ elseif (preg_match('/<(br|div|font|img|li|span|strong|table)\s+[^<>\/]*\/>/i',$msg)) return true;
elseif (preg_match('/&[A-Z0-9]{1,6};/i',$msg)) return true; // Html entities names (http://www.w3schools.com/tags/ref_entities.asp)
elseif (preg_match('/[0-9]{2,3};/i',$msg)) return true; // Html entities numbers (http://www.w3schools.com/tags/ref_entities.asp)
return false;
@@ -3688,7 +3680,7 @@ function dol_textishtml($msg,$option=0)
}
/**
- * Concat 2 descriptions (second one after first one)
+ * Concat 2 descriptions (second one after first one with a new line separator if required)
* text1 html + text2 html => text1 + '
' + text2
* text1 html + text2 txt => text1 + '
' + dol_nl2br(text2)
* text1 txt + text2 html => dol_nl2br(text1) + '
' + text2
diff --git a/test/phpunit/FunctionsLibTest.php b/test/phpunit/FunctionsLibTest.php
index 3707a875238..b8414dd170e 100755
--- a/test/phpunit/FunctionsLibTest.php
+++ b/test/phpunit/FunctionsLibTest.php
@@ -168,20 +168,35 @@ class FunctionsLibTest extends PHPUnit_Framework_TestCase
$input='xxx yyy zzz';
$after=dol_textishtml($input);
$this->assertTrue($after);
- $input='xxx
';
- $after=dol_textishtml($input);
- $this->assertTrue($after);
$input='text with some div
';
$after=dol_textishtml($input);
$this->assertTrue($after);
$input='text with HTML entities';
$after=dol_textishtml($input);
$this->assertTrue($after);
+ $input='xxx
';
+ $after=dol_textishtml($input);
+ $this->assertTrue($after);
+ $input='xxx
';
+ $after=dol_textishtml($input);
+ $this->assertTrue($after);
+ $input='xxx
';
+ $after=dol_textishtml($input);
+ $this->assertTrue($after);
+ $input='xxx
';
+ $after=dol_textishtml($input);
+ $this->assertTrue($after);
// False
$input='xxx < br>';
$after=dol_textishtml($input);
$this->assertFalse($after);
+ $input='xxx '; // is html, assertFalse($after);
+ $input='xxx ';
+ $after=dol_textishtml($input);
+ $this->assertFalse($after);
}
@@ -208,6 +223,53 @@ class FunctionsLibTest extends PHPUnit_Framework_TestCase
return true;
}
+ /**
+ * testDolConcat
+ *
+ * @return boolean
+ */
+ public function testDolConcat()
+ {
+ $text1="A string 1"; $text2="A string 2"; // text 1 and 2 are text, concat need only \n
+ $after=dol_concatdesc($text1, $text2);
+ $this->assertEquals("A string 1\nA string 2",$after);
+
+ $text1="A
string 1"; $text2="A string 2"; // text 1 is html, concat need
\n
+ $after=dol_concatdesc($text1, $text2);
+ $this->assertEquals("A
string 1
\nA string 2",$after);
+
+ $text1="A string 1"; $text2="A string 2"; // text 2 is html, concat need
\n
+ $after=dol_concatdesc($text1, $text2);
+ $this->assertEquals("A string 1
\nA string 2",$after);
+
+ return true;
+ }
+
+
+ /**
+ * testDolStringNohtmltag
+ *
+ * @return boolean
+ */
+ public function testDolStringNohtmltag()
+ {
+ $text="A\nstring\n";
+ $after=dol_string_nohtmltag($text,0);
+ $this->assertEquals("A\nstring",$after,"test1");
+
+ $text="A string\n\nwith html tag and '<' chars
\n";
+ $after=dol_string_nohtmltag($text, 0);
+ $this->assertEquals("A string\n\nwith html tag and '<' chars",$after,"test2");
+
+ $text="A string\n\nwith tag with < chars
\n";
+ $after=dol_string_nohtmltag($text, 1);
+ $this->assertEquals("A string with tag with < chars",$after,"test3");
+
+ return true;
+ }
+
+
+
/**
* testDolHtmlEntitiesBr
*