From f148dc2402aff409ab122aed45684538fba6e16e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sun, 14 May 2017 16:11:58 +0300 Subject: [PATCH] fix and test ">" being part of email "comment". #127 Example Email-header: "Foo Description: The example email-header should be valid according to https://tools.ietf.org/html/rfc2822#section-3.4 but the function AdressList.php/addFromString matches it incorrect. The result has the following form: "bar .*?)<(?P[^>]+)>|(?P.+))$/', $address, $matches)) { + if (! preg_match('/^((?P.*)<(?P[^>]+)>|(?P.+))$/', $address, $matches)) { throw new Exception\InvalidArgumentException('Invalid address format'); } diff --git a/test/AddressListTest.php b/test/AddressListTest.php index 87e37ce2..000a8adc 100644 --- a/test/AddressListTest.php +++ b/test/AddressListTest.php @@ -14,10 +14,13 @@ /** * @group Zend_Mail - * @covers Zend\Mail\AddressList + * @covers \Zend\Mail\AddressList */ class AddressListTest extends \PHPUnit_Framework_TestCase { + /** @var AddressList $list */ + private $list; + public function setUp() { $this->list = new AddressList(); diff --git a/test/HeadersTest.php b/test/HeadersTest.php index 64cfbccd..feac3ff9 100644 --- a/test/HeadersTest.php +++ b/test/HeadersTest.php @@ -14,7 +14,7 @@ /** * @group Zend_Mail - * @covers Zend\Mail\Headers + * @covers \Zend\Mail\Headers */ class HeadersTest extends \PHPUnit_Framework_TestCase { @@ -479,4 +479,36 @@ public function testAddressListGetEncodedFieldValueWithUtf8Domain() $encodedValue = $to->getFieldValue(Header\HeaderInterface::FORMAT_ENCODED); $this->assertEquals('local-part@xn---umlaut-4wa.de', $encodedValue); } + + /** + * Test ">" being part of email "comment". + * + * Example Email-header: + * "Foo '); + + $address = $to->getAddressList()->get('foo.bar@test.com'); + $this->assertEquals('õlu getName()); + $this->assertEquals('foo.bar@test.com', $address->getEmail()); + + $encodedValue = $to->getFieldValue(Header\HeaderInterface::FORMAT_ENCODED); + $this->assertEquals('=?UTF-8?Q?=C3=B5lu=20', $encodedValue); + + $encodedValue = $to->getFieldValue(Header\HeaderInterface::FORMAT_RAW); + // FIXME: shouldn't the "name" part be in quotes? + $this->assertEquals('õlu ', $encodedValue); + } }