8000 Merge branch '4.3' into 4.4 · symfony/symfony@7aedfe7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7aedfe7

Browse files
committed
Merge branch '4.3' into 4.4
* 4.3: [Mime] Trim and remove line breaks from NamedAddress name arg
2 parents 451daa0 + 58439e3 commit 7aedfe7

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/Symfony/Component/Mime/Address.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ public function __construct(string $address, string $name = '')
3939
self::$validator = new EmailValidator();
4040
}
4141

42-
if (!self::$validator->isValid($address, new RFCValidation())) {
42+
$this->address = trim($address);
43+
$this->name = trim(str_replace(["\n", "\r"], '', $name));
44+
45+
if (!self::$validator->isValid($this->address, new RFCValidation())) {
4346
throw new RfcComplianceException(sprintf('Email "%s" does not comply with addr-spec of RFC 2822.', $address));
4447
}
45-
46-
$this->address = $address;
47-
$this->name = $name;
4848
}
4949

5050
public function getAddress(): string

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,18 @@ public function testCreateArrayWrongArg()
6363
$this->expectException(\InvalidArgumentException::class);
6464
Address::createArray([new \stdClass()]);
6565
}
66+
67+
/**
68+
* @dataProvider nameEmptyDataProvider
69+
*/
70+
public function testNameEmpty(string $name)
71+
{
72+
$mail = 'mail@example.org';
73+
$this->assertSame($mail, (new Address($mail, $name))->toString());
74+
}
75+
76+
public function nameEmptyDataProvider(): array
77+
{
78+
return [[''], [' '], [" \r\n "]];
79+
}
6680
}

0 commit comments

Comments
 (0)
0