Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ef11c2c

Browse filesBrowse files
committed
bug #39717 [TwigBridge] Remove full head content in HTML to text converter (pupaxxo)
This PR was merged into the 4.4 branch. Discussion ---------- [TwigBridge] 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 | Q | A | ------------- | --- | Branch? | 4.4 <!-- see below --> | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Never break backward compatibility (see https://symfony.com/bc). - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too.) - Features and deprecations must be submitted against branch 5.x. --> Without the `s` flag the preg_replace match only head (or style) tags on a single line Commits ------- 9e6baee Remove full head content in HTML to text converter
2 parents 426bf96 + 9e6baee commit ef11c2c
Copy full SHA for ef11c2c

File tree

2 files changed

+18
-1
lines changed
Filter options

2 files changed

+18
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Mime/BodyRenderer.php
+1-1Lines 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(preg_replace('{<(head|style)\b.*?</\1>}i', '', $html));
77+
return strip_tags(preg_replace('{<(head|style)\b.*?</\1>}is', '', $html));
7878
}
7979
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Tests/Mime/BodyRendererTest.php
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,23 @@ public function testRenderHtmlOnly()
3737
$this->assertEquals(str_replace('=', '=3D', $html), $body->getParts()[1]->bodyToString());
3838
}
3939

40+
public function testRenderMultiLineHtmlOnly()
41+
{
42+
$html = <<<HTML
43+
<head>
44+
<style type="text/css">
45+
css
46+
</style>
47+
</head>
48+
<b>HTML</b>
49+
HTML;
50+
$email = $this->prepareEmail(null, $html);
51+
$body = $email->getBody();
52+
$this->assertInstanceOf(AlternativePart::class, $body);
53+
$this->assertEquals('HTML', str_replace(["\r", "\n"], '', $body->getParts()[0]->bodyToString()));
54+
$this->assertEquals(str_replace(['=', "\n"], ['=3D', "\r\n"], $html), $body->getParts()[1]->bodyToString());
55+
}
56+
4057
public function testRenderHtmlOnlyWithTextSet()
4158
{
4259
$email = $this->prepareEmail(null, '<b>HTML</b>');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.