Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 96d2d19

Browse files
committed
bug #36995 [TwigBridge] fix fallback html-to-txt body converter (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [TwigBridge] fix fallback html-to-txt body converter | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Right now, the content of the `<head>` and `<style>` are dumped as text. This fixes it. Of course, use `league/html-to-markdown` if you need a better parser. Commits ------- 6f59d60 [TwigBridge] fix fallback html-to-txt body converter
2 parents 15d4f7a + 6f59d60 commit 96d2d19

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/Symfony/Bridge/Twig/Mime/BodyRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,6 @@ private function convertHtmlToText(string $html): string
7474
return $this->converter->convert($html);
7575
}
7676

77-
return strip_tags($html);
77+
return strip_tags(preg_replace('{<(head|style)\b.*?</\1>}i', '', $html));
7878
}
7979
}

src/Symfony/Bridge/Twig/Tests/Mime/BodyRendererTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ public function testRenderTextOnly(): void
2929

3030
public function testRenderHtmlOnly(): void
3131
{
32-
$email = $this->prepareEmail(null, '<b>HTML</b>');
32+
$html = '<head>head</head><b>HTML</b><style type="text/css">css</style>';
33+
$email = $this->prepareEmail(null, $html);
3334
$body = $email->getBody();
3435
$this->assertInstanceOf(AlternativePart::class, $body);
3536
$this->assertEquals('HTML', $body->getParts()[0]->bodyToString());
36-
$this->assertEquals('<b>HTML</b>', $body->getParts()[1]->bodyToString());
37+
$this->assertEquals(str_replace('=', '=3D', $html), $body->getParts()[1]->bodyToString());
3738
}
3839

3940
public function testRenderHtmlOnlyWithTextSet(): void

0 commit comments

Comments
 (0)