diff --git a/program/lib/Roundcube/rcube_washtml.php b/program/lib/Roundcube/rcube_washtml.php index 513bacef4..477a3f17f 100644 --- a/program/lib/Roundcube/rcube_washtml.php +++ b/program/lib/Roundcube/rcube_washtml.php @@ -782,17 +782,28 @@ class rcube_washtml */ protected function fix_html5($html) { + // There might be content before html/body tag, we'll move it to the body + // We'll wrap it by a div container, it's an invalid HTML anyway + if (strpos($html, '<')) { + $pos = stripos($html, '' . substr($html, 0, $pos) . ''; + $html = substr($html, $pos); + } + // HTML5 requires or (#6713) // https://github.com/Masterminds/html5-php/issues/166 - if (!preg_match('/<(head|body)/i', $html)) { - $pos = stripos($html, '', $pos); - $html = substr_replace($html, '', $pos + 1, 0); + $html = substr_replace($html, ($body_pos === false ? '' : '') . $prefix, $pos + 1, 0); } } diff --git a/tests/Framework/Washtml.php b/tests/Framework/Washtml.php index 1e66c809e..2ffebec27 100644 --- a/tests/Framework/Washtml.php +++ b/tests/Framework/Washtml.php @@ -471,5 +471,17 @@ class Framework_Washtml extends PHPUnit_Framework_TestCase $washed = $washer->wash($html); $this->assertContains('First line', $washed); + + // Not really valid HTML, but because its common in email world + // and because it works with DOMDocument, we make sure its supported + $html = 'First line
Second line'; + $washed = $washer->wash($html); + + $this->assertContains('First line', $washed); + + $html = 'First line
Second line'; + $washed = $washer->wash($html); + + $this->assertContains('First line', $washed); } }