8000 [Mime] Regression with double doubleticks from #39866 · Issue #40652 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
8000

[Mime] Regression with double doubleticks from #39866 #40652

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

Closed
lolli42 opened this issue Mar 31, 2021 · 1 comment
Closed

[Mime] Regression with double doubleticks from #39866 #40652

lolli42 opened this issue Mar 31, 2021 · 1 comment

Comments

@lolli42
Copy link
lolli42 commented Mar 31, 2021

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.

@gilbertsoft
Copy link
Contributor

Finally we solved this issue within the TYPO3 Core by using Address::create() instead of new Address().

@lolli42 lolli42 closed this as completed Apr 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
0