diff --git a/CHANGELOG.md b/CHANGELOG.md index e7ac968e..edd5df4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,9 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed -- Nothing. +- [#226](https://github.com/zendframework/zend-mail/pull/226) fixes how `Zend\Mail\Header\ListParser::parse()` parses the string if a different quote delimiter + is found when already in quote as described in [#222](https://github.com/zendframework/zend-mail/issues/222). Merges test from + [#224](https://github.com/zendframework/zend-mail/pull/224). ## 2.10.0 - 2018-06-07 diff --git a/src/Header/ListParser.php b/src/Header/ListParser.php index d523d011..06a370d1 100644 --- a/src/Header/ListParser.php +++ b/src/Header/ListParser.php @@ -76,6 +76,12 @@ public static function parse($value, array $delims = self::CHAR_DELIMS) continue; } + // If already in quote and the character does not match the previously + // matched quote delimiter, we're done here. + if ($inQuote) { + continue; + } + // Otherwise, we're starting a quoted string. $inQuote = true; $currentQuoteDelim = $char; diff --git a/test/AddressListTest.php b/test/AddressListTest.php index 3db6805a..d63f52ec 100644 --- a/test/AddressListTest.php +++ b/test/AddressListTest.php @@ -144,4 +144,26 @@ public function testSemicolonSeparator() $this->assertTrue($addressList->has('asda.fasd@example.net')); $this->assertTrue($addressList->has('root@example.org')); } + + /** + * If name-field is quoted with "", then ' inside it should not treated as terminator, but as value. + */ + public function testMixedQuotesInName() + { + $header = '"Bob O\'Reilly" ,blah@example.com'; + + // In previous versions, this throws: + // 'Bob O'Reilly ,blah' can not be matched against dot-atom format + // hence the try/catch block, to allow finding the root cause. + try { + $to = Header\To::fromString('To:' . $header); + } catch (InvalidArgumentException $e) { + $this->fail('Header\To::fromString should not throw. Exception message: ' . $e->getMessage()); + } + + $addressList = $to->getAddressList(); + $this->assertTrue($addressList->has('bob@example.com')); + $this->assertTrue($addressList->has('blah@example.com')); + $this->assertEquals("Bob O'Reilly", $addressList->get('bob@example.com')->getName()); + } }