Browse Source

Fix extra leading newlines in plain text converted from HTML (#8973)

pull/8983/head
Aleksander Machniak 2 years ago
parent
commit
e69cd1b5a6
  1. 1
      CHANGELOG.md
  2. 9
      program/lib/Roundcube/rcube_html2text.php
  3. 19
      tests/Framework/Html2text.php

1
CHANGELOG.md

@ -32,6 +32,7 @@
- Fix bug where it wasn't possible to scroll lists by clicking middle mouse button (#8942)
- Fix bug where label text in a single-input dialog could be partially invisible in some locales (#8905)
- Fix bug where LDAP (fulltext) search didn't work without 'search_fields' in config (#8874)
- Fix extra leading newlines in plain text converted from HTML (#8973)
## Release 1.6.1

9
program/lib/Roundcube/rcube_html2text.php

@ -143,9 +143,10 @@ class rcube_html2text
*/
protected $search = [
'/\r/', // Non-legal carriage return
'/<head[^>]*>.*?<\/head>/is', // <head>
'/<script[^>]*>.*?<\/script>/is', // <script>
'/<style[^>]*>.*?<\/style>/is', // <style>
'/\n*<\/?html>\n*/is', // <html>
'/\n*<head[^>]*>.*?<\/head>\n*/is', // <head>
'/\n*<script[^>]*>.*?<\/script>\n*/is', // <script>
'/\n*<style[^>]*>.*?<\/style>\n*/is', // <style>
'/[\n\t]+/', // Newlines and tabs
'/<p[^>]*>/i', // <p>
'/<\/p>[\s\n\t]*<div[^>]*>/i', // </p> before <div>
@ -172,6 +173,7 @@ class rcube_html2text
*/
protected $replace = [
'', // Non-legal carriage return
'', // <html>|</html>
'', // <head>
'', // <script>
'', // <style>
@ -502,6 +504,7 @@ class rcube_html2text
if (($pos = stripos($text, '<body')) !== false) {
$pos = strpos($text, '>', $pos);
$text = substr($text, $pos + 1);
$text = ltrim($text);
}
// Run our defined tags search-and-replace

19
tests/Framework/Html2text.php

@ -71,6 +71,25 @@ class rc_html2text extends PHPUnit\Framework\TestCase
'in' => '<b><strong>&#347;</strong></b>',
'out' => 'ś',
],
12 => [
'title' => 'Full HTML handling (html tag only)',
'in' => "<html>\n<p>test</p></html>",
'out' => 'test',
],
13 => [
'title' => 'Full HTML handling (html+head tags)',
'in' => '<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head>'
. "\n<p>test</p></html>\n",
'out' => 'test',
],
14 => [
'title' => 'Full HTML handling (html+head+body tags)',
'in' => '<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head>' . "\n"
. '<body style="font-size: 10pt; font-family: Verdana,Geneva,sans-serif">' . "\n"
. '<p>test</p>'
. '</body></html>',
'out' => 'test',
],
];
}

Loading…
Cancel
Save