diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 071b7a3b794..3f7d9b8af09 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -5389,7 +5389,7 @@ function picto_required() */ function dol_string_nohtmltag($stringtoclean, $removelinefeed = 1, $pagecodeto = 'UTF-8', $strip_tags = 0) { - if ($removelinefeed == 2) $stringtoclean = preg_replace('/]*>\n+/ims', '
', $stringtoclean); + if ($removelinefeed == 2) $stringtoclean = preg_replace('/]*>(\n|\r)+/ims', '
', $stringtoclean); $temp = preg_replace('/]*>/i', "\n", $stringtoclean); if ($strip_tags) { diff --git a/test/phpunit/FunctionsLibTest.php b/test/phpunit/FunctionsLibTest.php index 1081b3bba23..edbfea239ef 100644 --- a/test/phpunit/FunctionsLibTest.php +++ b/test/phpunit/FunctionsLibTest.php @@ -520,15 +520,19 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase $text="A string
\n
\n\nwith html tag
\n"; $after=dol_string_nohtmltag($text, 0); - $this->assertEquals("A string\n\n\n\n\nwith html tag", $after, "test2a 2 br and 3 \n give 5 \n"); + $this->assertEquals("A string\n\n\n\n\nwith html tag", $after, 'test2a 2 br and 3 \n give 5 \n'); $text="A string
\n
\n\nwith html tag
\n"; $after=dol_string_nohtmltag($text, 1); - $this->assertEquals("A string with html tag", $after, "test2b 2 br and 3 \n give 1 space"); + $this->assertEquals("A string with html tag", $after, 'test2b 2 br and 3 \n give 1 space'); $text="A string
\n
\n\nwith html tag
\n"; $after=dol_string_nohtmltag($text, 2); - $this->assertEquals("A string\n\nwith html tag", $after, "test2c 2 br and 3 \n give 2 \n"); + $this->assertEquals("A string\n\nwith html tag", $after, 'test2c 2 br and 3 \n give 2 \n'); + + $text="A string
\r\n
\r\n\r\nwith html tag
\n"; + $after=dol_string_nohtmltag($text, 2); + $this->assertEquals("A string\n\nwith html tag", $after, 'test2c 2 br and 3 \r\n give 2 \n'); $text="A string
Another string"; $after=dol_string_nohtmltag($text, 0);