Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Treat quote as value if already in quote using another delimiter #226

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 desbrided in [#222](https://github.com/zendframework/zend-mail/issues/222). Merges test from
silvadiego marked this conversation as resolved.
Show resolved Hide resolved
[#224](https://github.com/zendframework/zend-mail/pull/224).

## 2.10.0 - 2018-06-07

Expand Down
6 changes: 6 additions & 0 deletions src/Header/ListParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions test/AddressListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,26 @@ public function testSemicolonSeparator()
$this->assertTrue($addressList->has('[email protected]'));
$this->assertTrue($addressList->has('[email protected]'));
}

/**
* If name-field is quoted with "", then ' inside it should not treated as terminator, but as value.
*/
public function testMixedQuotesInName()
{
$header = '"Bob O\'Reilly" <[email protected]>,[email protected]';

// In previous versions, this throws:
// 'Bob O'Reilly <[email protected]>,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('[email protected]'));
$this->assertTrue($addressList->has('[email protected]'));
$this->assertEquals("Bob O'Reilly", $addressList->get('[email protected]')->getName());
}
}