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

Commit c89ff21

Browse filesBrowse files
committed
[Mime] Escape commas in address names
1 parent d23b74e commit c89ff21
Copy full SHA for c89ff21

File tree

Expand file treeCollapse file tree

2 files changed

+12
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-1
lines changed

‎src/Symfony/Component/Mime/Address.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mime/Address.php
+6-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mime/Tests/AddressTest.php
+6Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.