Remove full head content in HTML to text converter

When extracting text from HTML part all the content between opening and closing tag should be removed
This commit is contained in:
Andrea Ruggiero 2021-01-04 21:57:14 +01:00 committed by Andrea Ruggiero
parent 426bf9640a
commit 9e6baee9f3
No known key found for this signature in database
GPG Key ID: 6C96D1C51EA7A880
2 changed files with 18 additions and 1 deletions

View File

@ -74,6 +74,6 @@ final class BodyRenderer implements BodyRendererInterface
return $this->converter->convert($html);
}
return strip_tags(preg_replace('{<(head|style)\b.*?</\1>}i', '', $html));
return strip_tags(preg_replace('{<(head|style)\b.*?</\1>}is', '', $html));
}
}

View File

@ -37,6 +37,23 @@ class BodyRendererTest extends TestCase
$this->assertEquals(str_replace('=', '=3D', $html), $body->getParts()[1]->bodyToString());
}
public function testRenderMultiLineHtmlOnly()
{
$html = <<<HTML
<head>
<style type="text/css">
css
</style>
</head>
<b>HTML</b>
HTML;
$email = $this->prepareEmail(null, $html);
$body = $email->getBody();
$this->assertInstanceOf(AlternativePart::class, $body);
$this->assertEquals('HTML', str_replace(["\r", "\n"], '', $body->getParts()[0]->bodyToString()));
$this->assertEquals(str_replace(['=', "\n"], ['=3D', "\r\n"], $html), $body->getParts()[1]->bodyToString());
}
public function testRenderHtmlOnlyWithTextSet()
{
$email = $this->prepareEmail(null, '<b>HTML</b>');