[Mime] Trim and remove line breaks from NamedAddress name arg

This commit is contained in:
Emirald Mateli 2019-08-16 21:42:36 +02:00 committed by Fabien Potencier
parent 6d6cea2baa
commit e491e3a594
3 changed files with 19 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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());
}
}