diff --git a/api/src/Mail/Html.php b/api/src/Mail/Html.php index 0ec923a5e0..ceb7ff0c34 100644 --- a/api/src/Mail/Html.php +++ b/api/src/Mail/Html.php @@ -492,7 +492,11 @@ class Html return $html; } - $dom = \DOMDocument::loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD | LIBXML_NOBLANKS); + $dom = new \DOMDocument('1.0','UTF-8'); + $dom->loadHTML( + ''. Api\Translation::convert($html,false, 'utf8'), + LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD | LIBXML_NOBLANKS + ); if(!$dom) { // Failed to parse @@ -508,14 +512,23 @@ class Html $list_text = "\r\n"; $item_count = 0; $prefix = $list_type == 'ul' ? ' * ' : '. '; - foreach($list->getElementsByTagName('li') as $element) + $elements = $list->getElementsByTagName('li'); + foreach($elements as $element) { - $list_text .= ($list_type == 'ol' ? ' '. ++$item_count : '') . $prefix . $element->textContent . "\r\n"; + if($element->tagName == 'li') + { + $list_text .= ($list_type == 'ol' ? ' '. ++$item_count : '') . $prefix . $element->textContent . "\r\n"; + } + else + { + $list_text .= $element->nodeValue; + } } $list->parentNode->replaceChild($dom->createTextNode($list_text), $list); } } + $dom->removeChild($dom->firstChild); return $dom->saveHTML(); } diff --git a/api/tests/Mail/HtmlTest.php b/api/tests/Mail/HtmlTest.php index 7e791d4b23..4808fc796c 100644 --- a/api/tests/Mail/HtmlTest.php +++ b/api/tests/Mail/HtmlTest.php @@ -50,17 +50,43 @@ class HtmlTest extends TestCase { ['Not actually HTML', 'Not actually HTML'], ['HTML, but NO list here', 'HTML, but NO list here'], ["

Unordered list:

\r\nPost text

", - "

Unordered list:\r\n * First\r\n * Second\r\n * Third\r\n

\r\nPost text

\n"], + "

Unordered list:

\r\n * First\r\n * Second\r\n * Third\r\n

\r\nPost text

\n"], ["Ordered list:". "
  1. First
  2. \r\n" . "
  3. Second
  4. \r\n" . "
  5. Third
  6. \r\n" . "
Post text", - "

Ordered list:\r\n" + "

Ordered list:

\r\n" . " 1. First\r\n" . " 2. Second\r\n" . " 3. Third\r\n" - . "

Post text

\n"], + . "

Post text

\n"], + [ + ' +
    +
  1. Nummerierung 
  2. +
  3. zweitens
  4. +
  5. drittens
  6. +
  7. viertens
  8. +
+

dann normaler Text

+ +
 
', + "\r\n 1. Nummerierung \r + 2. zweitens\r + 3. drittens\r + 4. viertens\r +

dann normaler Text

\r + * aufzählung\r + * mit verschiedenen punkten\r + * dritter spiegelstrich\r + * vierter strich\r\n
 
\n" + ] ); } }