Closed
Description
Symfony version(s) affected: 4.4.21 5.5.6
Description
Adding a name "Foo"
leads to double doubleticks since #39866
How to reproduce
--- a/src/Symfony/Component/Mime/Tests/AddressTest.php
+++ b/src/Symfony/Component/Mime/Tests/AddressTest.php
@@ -159,4 +159,10 @@ class AddressTest extends TestCase
$address = new Address('fabien@symfony.com', 'Fabien, "Potencier');
$this->assertSame('"Fabien, \"Potencier" <fabien@symfony.com>', $address->toString());
}
+
+ public function testEncodeNameIfNameIsWrappedByDoubleTicks()
+ {
+ $address = new Address('fabien@symfony.com', '"Fabien Potencier"');
+ $this->assertSame('"Fabien Potencier" <fabien@symfony.com>', $address->toString());
+ }
}
1) Symfony\Component\Mime\Tests\AddressTest::testEncodeNameIfNameIsWrappedByDoubleTicks
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'"Fabien Potencier" <fabien@symfony.com>'
+'"\"Fabien Potencier\"" <fabien@symfony.com>'
Possible Solution
diff --git a/src/Symfony/Component/Mime/Address.php b/src/Symfony/Component/Mime/Address.php
index 61d35e39e9..a3882f1c7a 100644
--- a/src/Symfony/Component/Mime/Address.php
+++ b/src/Symfony/Component/Mime/Address.php
@@ -87,7 +87,7 @@ final class Address
return '';
}
- return sprintf('"%s"', preg_replace('/"/u', '\"', $this->getName()));
+ return sprintf('"%s"', preg_replace('/"/u', '\"', trim($this->getName(), '"')));
}
/**
Note this is kinda unfortunate currently: Previous symfony/mailer packages did not add the surrounding double ticks on their own, so we have to expect that address names have been set as "John Doe"
to end up with "John Doe" <foo@example.com>
. This now leads to "\"John Doe\"" <foo@example.com>
.
It would be good if that could be mitigated by trimming eventual given outer doubleticks.
For now, we'll probably set the new package versions as conflict to see how this issue ends up and to not risk a regression on our side.