Browse Source

FIX dol_string_nohtmltag when there is html with windows EOL "<br>\r\n"

Laurent Destailleur 5 years ago
parent
commit
3250b13f4a
2 changed files with 8 additions and 4 deletions
  1. 1 1
      htdocs/core/lib/functions.lib.php
  2. 7 3
      test/phpunit/FunctionsLibTest.php

+ 1 - 1
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('/<br[^>]*>\n+/ims', '<br>', $stringtoclean);
+	if ($removelinefeed == 2) $stringtoclean = preg_replace('/<br[^>]*>(\n|\r)+/ims', '<br>', $stringtoclean);
 	$temp = preg_replace('/<br[^>]*>/i', "\n", $stringtoclean);
 
 	if ($strip_tags) {

+ 7 - 3
test/phpunit/FunctionsLibTest.php

@@ -520,15 +520,19 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase
 
         $text="A <b>string<b><br>\n<br>\n\nwith html tag<br>\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 <b>string<b><br>\n<br>\n\nwith html tag<br>\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 <b>string<b><br>\n<br>\n\nwith html tag<br>\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 <b>string<b><br>\r\n<br>\r\n\r\nwith html tag<br>\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<br>Another string";
         $after=dol_string_nohtmltag($text, 0);