diff --git a/htdocs/includes/odtphp/odf.php b/htdocs/includes/odtphp/odf.php index abf12c66e0c..1d097e95975 100644 --- a/htdocs/includes/odtphp/odf.php +++ b/htdocs/includes/odtphp/odf.php @@ -167,14 +167,13 @@ class Odf { $value = html_entity_decode($value, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401); - // fix breaklines... - $value = str_replace("
", "
", $value); + // fix breaklines. + $value = preg_replace('/<[ ]*br[ ]*\/?>/', "
", $value); $convertedValue = $value; // Check if the value includes html tags if ($this->_hasHtmlTag($value) === true) { - // Note: allowing many tags is supported on PHP >7.4 . For older versions, this will strip all HTML tags. - $value = strip_tags($value, ['
', '', '', '', '', '', '', '', '', '']); + $value = strip_tags($value, '
'); // Default styles for strong/b, i/em, u, s, sub & sup $automaticStyles = array( diff --git a/test/phpunit/ODFTest.php b/test/phpunit/ODFTest.php index c4eeee3f8bd..fdf31140b11 100644 --- a/test/phpunit/ODFTest.php +++ b/test/phpunit/ODFTest.php @@ -155,101 +155,87 @@ class ODFTest extends PHPUnit\Framework\TestCase 'to_convert' => 'Simple string', 'encode' => true, 'charset' => null, - 'expected7.4' => 'Simple string', - 'expected7.3' => 'Simple string' + 'expected' => 'Simple string', ], 2 => [ 'to_convert' => 'Simple string', 'encode' => false, 'charset' => null, - 'expected7.4' => 'Simple string', - 'expected7.3' => 'Simple string' + 'expected' => 'Simple string', ], 3 => [ 'to_convert' => "Simple string\nwith line break", 'encode' => true, 'charset' => null, - 'expected7.4' => "Simple stringwith line break", - 'expected7.3' => "Simple stringwith line break" + 'expected' => "Simple stringwith line break", ], 4 => [ 'to_convert' => "Simple string\nwith line break", 'encode' => false, 'charset' => null, - 'expected7.4' => "Simple stringwith line break", - 'expected7.3' => "Simple stringwith line break" + 'expected' => "Simple stringwith line break", ], // Special chars 5 => [ 'to_convert' => 'One&two', 'encode' => true, 'charset' => null, - 'expected7.4' => 'One&two', - 'expected7.3' => 'One&two' + 'expected' => 'One&two', ], 6 => [ 'to_convert' => 'One&two', 'encode' => false, 'charset' => null, - 'expected7.4' => 'One&two', - 'expected7.3' => 'One&two' + 'expected' => 'One&two', ], 7 => [ 'to_convert' => "/a&él'èàüöç€Ğ~<>", 'encode' => true, 'charset' => null, - 'expected7.4' => utf8_encode("/a&él'èàüöç€Ğ~<>"), - 'expected7.3' => utf8_encode("/a&él'èàüöç€Ğ~<>") + 'expected' => utf8_encode("/a&él'èàüöç€Ğ~<>"), ], 8 => [ 'to_convert' => "/a&él'èàüöç€Ğ~<>", 'encode' => false, 'charset' => null, - 'expected7.4' => utf8_encode("/a&él'èàüöç€Ğ~<>"), - 'expected7.3' => utf8_encode("/a&él'èàüöç€Ğ~<>") + 'expected' => utf8_encode("/a&él'èàüöç€Ğ~<>"), ], // special chars with non-default charset 9 => [ 'to_convert' => "/a&él'èàüöç€Ğ~<>", 'encode' => true, 'charset' => 'UTF-16', - 'expected7.4' => "/a&él'èàüöç€Ğ~<>", - 'expected7.3' => "/a&él'èàüöç€Ğ~<>", + 'expected' => "/a&él'èàüöç€Ğ~<>", ], 10 => [ 'to_convert' => "/a&él'èàüöç€Ğ~<>", 'encode' => false, 'charset' => 'UTF-16', // When the charset differs from ISO-8859 string is not converted. - 'expected7.4' => "/a&él'èàüöç€Ğ~<>", - 'expected7.3' => "/a&él'èàüöç€Ğ~<>", + 'expected' => "/a&él'èàüöç€Ğ~<>", ], 11 => [ 'to_convert' => "Greater > than", 'encode' => true, 'charset' => null, - 'expected7.4' => utf8_encode("Greater > than"), - 'expected7.3' => utf8_encode("Greater > than"), + 'expected' => utf8_encode("Greater > than"), ], 12 => [ 'to_convert' => "Greater > than", 'encode' => false, 'charset' => null, - 'expected7.4' => utf8_encode("Greater > than"), - 'expected7.3' => utf8_encode("Greater > than"), + 'expected' => utf8_encode("Greater > than"), ], 13 => [ 'to_convert' => "Smaller < than", 'encode' => true, 'charset' => null, - 'expected7.4' => utf8_encode("Smaller < than"), - 'expected7.3' => utf8_encode("Smaller < than"), + 'expected' => utf8_encode("Smaller < than"), ], 14 => [ 'to_convert' => "Smaller < than", 'encode' => false, 'charset' => null, - 'expected7.4' => utf8_encode("Smaller < than"), - 'expected7.3' => utf8_encode("Smaller < than"), + 'expected' => utf8_encode("Smaller < than"), ], /** HTML **/ // break lines @@ -257,65 +243,56 @@ class ODFTest extends PHPUnit\Framework\TestCase 'to_convert' => "Break
line", 'encode' => true, 'charset' => null, - 'expected7.4' => utf8_encode("Breakline"), - 'expected7.3' => utf8_encode("Breakline"), + 'expected' => utf8_encode("Breakline"), ], 16 => [ 'to_convert' => "Break
line", 'encode' => false, 'charset' => null, - 'expected7.4' => utf8_encode("Breakline"), - 'expected7.3' => utf8_encode("Breakline"), + 'expected' => utf8_encode("Breakline"), ], 17 => [ 'to_convert' => "Break
line", 'encode' => true, 'charset' => null, - 'expected7.4' => utf8_encode("Breakline"), - 'expected7.3' => utf8_encode("Breakline"), + 'expected' => utf8_encode("Breakline"), ], 18 => [ 'to_convert' => "Break
line", 'encode' => false, 'charset' => null, - 'expected7.4' => utf8_encode("Breakline"), - 'expected7.3' => utf8_encode("Breakline"), + 'expected' => utf8_encode("Breakline"), ], // HTML tags 19 => [ 'to_convert' => "text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l'", 'encode' => false, 'charset' => 'UTF-8', - 'expected7.4' => 'text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l\'', - 'expected7.3' => 'text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l\'', + 'expected' => 'text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l\'', ], 20 => [ 'to_convert' => "text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l'", 'encode' => true, 'charset' => 'UTF-8', - 'expected7.4' => 'text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l'', - 'expected7.3' => 'text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l'', + 'expected' => 'text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l'', ], 21 => [ 'to_convert' => "text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l'", 'encode' => false, 'charset' => null, - 'expected7.4' => utf8_encode('text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l\''), - 'expected7.3' => utf8_encode('text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l\''), + 'expected' => utf8_encode('text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l\''), ], 22 => [ 'to_convert' => "text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l'", 'encode' => true, 'charset' => null, - 'expected7.4' => utf8_encode('text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l''), - 'expected7.3' => utf8_encode('text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l''), + 'expected' => utf8_encode('text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l''), ], 23 => [ 'to_convert' => "text with intricatedtags", 'encode' => true, 'charset' => null, - 'expected7.4' => utf8_encode('text with intricatedtags'), - 'expected7.3' => utf8_encode('text with intricatedtags'), + 'expected' => utf8_encode('text with intricatedtags'), ], // One can also pass html-encoded string to the method @@ -323,36 +300,31 @@ class ODFTest extends PHPUnit\Framework\TestCase 'to_convert' => 'One&two', 'encode' => true, 'charset' => null, - 'expected7.4' => 'One&two', - 'expected7.3' => 'One&two' + 'expected' => 'One&two', ], 25 => [ 'to_convert' => "text with <strong>strong, </strong><em>emphasis</em> and <u>underlined</u> words with <i>it@lic sp&ciàlchärs éè l'</i>", 'encode' => false, 'charset' => 'UTF-8', - 'expected7.4' => 'text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l\'', - 'expected7.3' => 'text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l\'', + 'expected' => 'text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l\'', ], 26 => [ 'to_convert' => "text with <strong>strong, </strong><em>emphasis</em> and <u>underlined</u> words with <i>it@lic sp&ciàlchärs éè l'</i>", 'encode' => true, 'charset' => 'UTF-8', - 'expected7.4' => 'text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l'', - 'expected7.3' => 'text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l'', + 'expected' => 'text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l'', ], 27 => [ 'to_convert' => "text with <strong>strong, </strong><em>emphasis</em> and <u>underlined</u> words with <i>it@lic sp&ciàlchärs éè l'</i>", 'encode' => false, 'charset' => null, - 'expected7.4' => utf8_encode('text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l\''), - 'expected7.3' => utf8_encode('text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l\''), + 'expected' => utf8_encode('text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l\''), ], 28 => [ 'to_convert' => "text with <strong>strong, </strong><em>emphasis</em> and <u>underlined</u> words with <i>it@lic sp&ciàlchärs éè l'</i>", 'encode' => true, 'charset' => null, - 'expected7.4' => utf8_encode('text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l''), - 'expected7.3' => utf8_encode('text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l''), + 'expected' => utf8_encode('text with strong, emphasis and underlined words with it@lic sp&ciàlchärs éè l''), ], // // TODO custom styles are not tested for now : the custom style have a custom ID based on time. Not random, but hard to mock or predict. generated in _replaceHtmlWithOdtTag() case 'span'. @@ -360,7 +332,7 @@ class ODFTest extends PHPUnit\Framework\TestCase // 'to_convert' => '123 trucmachin > truc < troc > tracbla bla', // 'encode' => true, // 'charset' => 'UTF-8', - // 'expected7.4' => "123 trucmachin > truc < troc > tracbla bla'", + // 'expected' => "123 trucmachin > truc < troc > tracbla bla'", // ], /* Tests that can evolve */ @@ -371,23 +343,20 @@ class ODFTest extends PHPUnit\Framework\TestCase 'to_convert' => '123 trucmachin > truc < troc > tracbla bla', 'encode' => true, 'charset' => null, - 'expected7.4' => "123 trucmachin > truc < troc > tracbla bla", - 'expected7.3' => "123 trucmachin > truc < troc > tracbla bla", + 'expected' => "123 trucmachin > truc < troc > tracbla bla", ], 30 => [ 'to_convert' => '123

Title

bla', 'encode' => true, 'charset' => null, - 'expected7.4' => "123 Title bla", - 'expected7.3' => "123 Title bla", + 'expected' => "123 Title bla", ], // HTML should not take \n into account, but only
. 31 => [ 'to_convert' => "text with strong text , a line\nbreak and underlined words with it@lic sp&ciàlchärs éè l'", 'encode' => false, 'charset' => 'UTF-8', - 'expected7.4' => 'text with strong text , a line'."\n".'break and underlined words with it@lic sp&ciàlchärs éè l\'', - 'expected7.3' => 'text with strong text , a line'."\n".'break and underlined words with it@lic sp&ciàlchärs éè l\'', + 'expected' => 'text with strong text , a line'."\n".'break and underlined words with it@lic sp&ciàlchärs éè l\'', ], ]; @@ -400,11 +369,7 @@ class ODFTest extends PHPUnit\Framework\TestCase } else { $res = $odf->convertVarToOdf($case['to_convert'], $case['encode']); } - if (version_compare(phpversion(), '7.4.0', '>=')) { - $this->assertEquals($res, $case['expected7.4']); - } else { - $this->assertEquals($res, $case['expected7.3']); - } + $this->assertEquals($res, $case['expected']); } print __METHOD__." result=".$result."\n";