[Mime] Trim and remove line breaks from NamedAddress name arg
This commit is contained in:
parent
6d6cea2baa
commit
e491e3a594
@ -40,11 +40,11 @@ class Address
|
||||
self::$validator = new EmailValidator();
|
||||
}
|
||||
|
||||
if (!self::$validator->isValid($address, new RFCValidation())) {
|
||||
$this->address = trim($address);
|
||||
|
||||
if (!self::$validator->isValid($this->address, new RFCValidation())) {
|
||||
throw new RfcComplianceException(sprintf('Email "%s" does not comply with addr-spec of RFC 2822.', $address));
|
||||
}
|
||||
|
||||
$this->address = $address;
|
||||
}
|
||||
|
||||
public function getAddress(): string
|
||||
|
@ -24,7 +24,7 @@ final class NamedAddress extends Address
|
||||
{
|
||||
parent::__construct($address);
|
||||
|
||||
$this->name = $name;
|
||||
$this->name = trim(str_replace(["\n", "\r"], '', $name));
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
|
@ -24,4 +24,19 @@ class NamedAddressTest extends TestCase
|
||||
$this->assertEquals('Fabien <fabien@xn--symfon-nwa.com>', $a->toString());
|
||||
$this->assertEquals('fabien@xn--symfon-nwa.com', $a->getEncodedAddress());
|
||||
}
|
||||
|
||||
public function nameEmptyDataProvider(): array
|
||||
{
|
||||
return [[''], [' '], [" \r\n "]];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider nameEmptyDataProvider
|
||||
*/
|
||||
public function testNameEmpty(string $name)
|
||||
{
|
||||
$mail = 'mail@example.org';
|
||||
|
||||
$this->assertSame($mail, (new NamedAddress($mail, $name))->getEncodedNamedAddress());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user