Merge branch '4.3' into 4.4

* 4.3:
  [Mime] Trim and remove line breaks from NamedAddress name arg
This commit is contained in:
Fabien Potencier 2019-08-21 10:50:18 +02:00
commit 7aedfe7079
2 changed files with 18 additions and 4 deletions

View File

@ -39,12 +39,12 @@ final class Address
self::$validator = new EmailValidator();
}
if (!self::$validator->isValid($address, new RFCValidation())) {
$this->address = trim($address);
$this->name = trim(str_replace(["\n", "\r"], '', $name));
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;
$this->name = $name;
}
public function getAddress(): string

View File

@ -63,4 +63,18 @@ class AddressTest extends TestCase
$this->expectException(\InvalidArgumentException::class);
Address::createArray([new \stdClass()]);
}
/**
* @dataProvider nameEmptyDataProvider
*/
public function testNameEmpty(string $name)
{
$mail = 'mail@example.org';
$this->assertSame($mail, (new Address($mail, $name))->toString());
}
public function nameEmptyDataProvider(): array
{
return [[''], [' '], [" \r\n "]];
}
}