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

[Mime] Don't require passing the encoder name to TextPart #58764

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
Nov 5, 2024
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
[Mime] Don't require passig the encoder name to TextPart
  • Loading branch information
javiereguiluz committed Nov 5, 2024
commit 2ce04c8824bb368621c8d53d84326c2718e59a59
6 changes: 3 additions & 3 deletions 6 src/Symfony/Component/Mime/Part/TextPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,13 @@ private function getEncoder(): ContentEncoderInterface
return self::$encoders[$this->encoding];
}

public static function addEncoder(string $name, ContentEncoderInterface $encoder): void
public static function addEncoder(ContentEncoderInterface $encoder): void
fabpot marked this conversation as resolved.
Show resolved Hide resolved
{
if (\in_array($name, self::DEFAULT_ENCODERS, true)) {
if (\in_array($encoder->getName(), self::DEFAULT_ENCODERS, true)) {
throw new InvalidArgumentException('You are not allowed to change the default encoders ("quoted-printable", "base64", and "8bit").');
}

self::$encoders[$name] = $encoder;
self::$encoders[$encoder->getName()] = $encoder;
}

private function chooseEncoding(): string
Expand Down
18 changes: 13 additions & 5 deletions 18 src/Symfony/Component/Mime/Tests/Part/TextPartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,29 @@ public function testEncoding()
public function testCustomEncoderNeedsToRegisterFirst()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('The encoding must be one of "quoted-printable", "base64", "8bit", "exception_test" ("upper_encoder" given).');
TextPart::addEncoder('exception_test', $this->createMock(ContentEncoderInterface::class));
new TextPart('content', 'utf-8', 'plain', 'upper_encoder');
$this->expectExceptionMessage('The encoding must be one of "quoted-printable", "base64", "8bit", "upper_encoder" ("this_encoding_does_not_exist" given).');

$upperEncoder = $this->createMock(ContentEncoderInterface::class);
$upperEncoder->method('getName')->willReturn('upper_encoder');

TextPart::addEncoder($upperEncoder);
new TextPart('content', 'utf-8', 'plain', 'this_encoding_does_not_exist');
}

public function testOverwriteDefaultEncoder()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('You are not allowed to change the default encoders ("quoted-printable", "base64", and "8bit").');
TextPart::addEncoder('8bit', $this->createMock(ContentEncoderInterface::class));

$base64Encoder = $this->createMock(ContentEncoderInterface::class);
$base64Encoder->method('getName')->willReturn('base64');

TextPart::addEncoder($base64Encoder);
}

public function testCustomEncoding()
{
TextPart::addEncoder('upper_encoder', new class implements ContentEncoderInterface {
TextPart::addEncoder(new class implements ContentEncoderInterface {
public function encodeByteStream($stream, int $maxLineLength = 0): iterable
{
$filter = stream_filter_append($stream, 'string.toupper', \STREAM_FILTER_READ);
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.