From 407a06d77522fab651dd5e056c9cefd713ccb93b Mon Sep 17 00:00:00 2001 From: Diego Silva Date: Sun, 17 Mar 2019 21:38:44 +0100 Subject: [PATCH 1/8] Treat quote as value if already in quote using another delimiter --- src/Header/ListParser.php | 6 ++++++ test/Header/ListParser.php | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 test/Header/ListParser.php 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/Header/ListParser.php b/test/Header/ListParser.php new file mode 100644 index 00000000..d58db87d --- /dev/null +++ b/test/Header/ListParser.php @@ -0,0 +1,26 @@ + + */ +class ListParserTest extends TestCase +{ + public function testParseIgnoreQuoteDelimiterIfAlreadyInQuote() + { + $parsed = ListParser::parse('"john\'doe" ,jane '); + $this->assertEquals($parsed, [ + '"john\'doe" ', + 'jane ' + ]); + } +} From 1ca467ca70da6f81a351cf9a6a66f730ded1b743 Mon Sep 17 00:00:00 2001 From: Diego Silva Date: Sun, 17 Mar 2019 21:53:22 +0100 Subject: [PATCH 2/8] CHANGELOG.md updated --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7ac968e..b2b1ae28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,8 @@ 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. ## 2.10.0 - 2018-06-07 From 376a5dccc43124c15641cff7c41a0a67a63fb5ed Mon Sep 17 00:00:00 2001 From: Diego Silva Date: Wed, 20 Mar 2019 17:56:25 +0100 Subject: [PATCH 3/8] Update Copyright year from 2018 to 2019 --- test/Header/ListParser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Header/ListParser.php b/test/Header/ListParser.php index d58db87d..1a61e2c5 100644 --- a/test/Header/ListParser.php +++ b/test/Header/ListParser.php @@ -1,7 +1,7 @@ Date: Tue, 5 Mar 2019 00:49:15 +0200 Subject: [PATCH 4/8] add test for #147 regression --- test/AddressListTest.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/AddressListTest.php b/test/AddressListTest.php index 3db6805a..c7d43ff5 100644 --- a/test/AddressListTest.php +++ b/test/AddressListTest.php @@ -144,4 +144,25 @@ 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()); + } } From 82290a68f0946aa5ffa64ec3399f70f96db90f0b Mon Sep 17 00:00:00 2001 From: Diego Silva Date: Wed, 20 Mar 2019 23:28:46 +0100 Subject: [PATCH 5/8] Removed ListParser tests file and cherry picked tests from pr 224 --- test/Header/ListParser.php | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 test/Header/ListParser.php diff --git a/test/Header/ListParser.php b/test/Header/ListParser.php deleted file mode 100644 index 1a61e2c5..00000000 --- a/test/Header/ListParser.php +++ /dev/null @@ -1,26 +0,0 @@ - - */ -class ListParserTest extends TestCase -{ - public function testParseIgnoreQuoteDelimiterIfAlreadyInQuote() - { - $parsed = ListParser::parse('"john\'doe" ,jane '); - $this->assertEquals($parsed, [ - '"john\'doe" ', - 'jane ' - ]); - } -} From 830696fea862620098b4ee523f5d175695f218ef Mon Sep 17 00:00:00 2001 From: Diego Silva Date: Thu, 21 Mar 2019 01:12:59 +0100 Subject: [PATCH 6/8] Fix cs --- test/AddressListTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/AddressListTest.php b/test/AddressListTest.php index c7d43ff5..d63f52ec 100644 --- a/test/AddressListTest.php +++ b/test/AddressListTest.php @@ -148,7 +148,8 @@ public function testSemicolonSeparator() /** * If name-field is quoted with "", then ' inside it should not treated as terminator, but as value. */ - public function testMixedQuotesInName() { + public function testMixedQuotesInName() + { $header = '"Bob O\'Reilly" ,blah@example.com'; // In previous versions, this throws: From ac9637e8239ef554054f21e7df3e1ceb5ad552bc Mon Sep 17 00:00:00 2001 From: Diego Silva Date: Thu, 21 Mar 2019 13:50:49 +0100 Subject: [PATCH 7/8] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2b1ae28..dbc58223 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,8 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed - [#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. + is found when already in quote as desbrided 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 From 2f644a98b8d2500f5d225dccaae185146c83e883 Mon Sep 17 00:00:00 2001 From: Diego Silva Date: Mon, 8 Jul 2019 14:59:53 +0200 Subject: [PATCH 8/8] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbc58223..edd5df4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,7 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed - [#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 desbrided in [#222](https://github.com/zendframework/zend-mail/issues/222). Merges test from + 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