10000 [TwigBridge] fix fallback html-to-txt body converter by nicolas-grekas · Pull Request #36995 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[TwigBridge] fix fallback html-to-txt body converter #36995

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[TwigBridge] fix fallback html-to-txt body converter
  • Loading branch information
nicolas-grekas committed May 28, 2020
commit 6f59d605083b619ee41b07add28c5cfd42357ad2
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Mime/BodyRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ private function convertHtmlToText(string $html): string
return $this->converter->convert($html);
}

return strip_tags($html);
return strip_tags(preg_replace('{<(head|style)\b.*?</\1>}i', '', $html));
}
}
5 changes: 3 additions & 2 deletions src/Symfony/Bridge/Twig/Tests/Mime/BodyRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ public function testRenderTextOnly(): void

public function testRenderHtmlOnly(): void
{
$email = $this->prepareEmail(null, '<b>HTML</b>');
$html = '<head>head</head><b>HTML</b><style type="text/css">css</style>';
$email = $this->prepareEmail(null, $html);
$body = $email->getBody();
$this->assertInstanceOf(AlternativePart::class, $body);
$this->assertEquals('HTML', $body->getParts()[0]->bodyToString());
$this->assertEquals('<b>HTML</b>', $body->getParts()[1]->bodyToString());
$this->assertEquals(str_replace('=', '=3D', $html), $body->getParts()[1]->bodyToString());
}

public function testRenderHtmlOnlyWithTextSet(): void
Expand Down
0