8000 [Mime] Escape commas in address names · symfony/symfony@c89ff21 · GitHub
[go: up one dir, main page]

Skip to content

Commit c89ff21

Browse files
committed
[Mime] Escape commas in address names
1 parent d23b74e commit c89ff21

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Symfony/Component/Mime/Address.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,12 @@ public function getEncodedAddress(): string
7777

7878
public function toString(): string
7979
{
80-
return ($n = $this->getName()) ? $n.' <'.$this->getEncodedAddress().'>' : $this->getEncodedAddress();
80+
return ($n = $this->getEncodedName()) ? $n.' <'.$this->getEncodedAddress().'>' : $this->getEncodedAddress();
81+
}
82+
83+
public function getEncodedName(): string
84+
{
85+
return sprintf('"%s"', str_replace('/"/u', '\"', $this->getName()));
8186
}
8287

8388
/**

src/Symfony/Component/Mime/Tests/AddressTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,10 @@ public function fromStringProvider()
153153
],
154154
];
155155
}
156+
157+
public function testEncodeNameIfNameContainsCommas()
158+
{
159+
$address = new Address('fabien@symfony.com', 'Fabien, "Potencier');
160+
$this->assertSame('"Fabien, \"Potencier" <fabien@symfony.com>', $address->toString());
161+
}
156162
}

0 commit comments

Comments
 (0)
0