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('[email protected]', 'Fabien, "Potencier');
$this->assertSame('"Fabien, \"Potencier" <[email protected]>', $address->toString());
}
+
+ public function testEncodeNameIfNameIsWrappedByDoubleTicks()
+ {
+ $address = new Address('[email protected]', '"Fabien Potencier"');
+ $this->assertSame('"Fabien Potencier" <[email protected]>', $address->toString());
+ }
}
1) Symfony\Component\Mime\Tests\AddressTest::testEncodeNameIfNameIsWrappedByDoubleTicks
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'"Fabien Potencier" <[email protected]>'
+'"\"Fabien Potencier\"" <[email protected]>'
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" <[email protected]>
. This now leads to "\"John Doe\"" <[email protected]>
.
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.