Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ All notable changes to this project will be documented in this file, in reverse

- [#82](https://github.com/laminas/laminas-mail/pull/82) fixes numerous issues in `Storage\Maildir`. This storage adapter was not working before and unit tests were disabled.

- [#75](https://github.com/laminas/laminas-mail/pull/75) fixes how `Laminas\Mail\Header\ListParser::parse()` parses the string with quotes.

## 2.10.0 - 2018-06-07

### Added
Expand Down
6 changes: 6 additions & 0 deletions src/Header/ListParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,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 @@ -200,4 +200,26 @@ public function testKey()
$this->list->next();
$this->assertSame('[email protected]', $this->list->key());
}

/**
* 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');
}

$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());
}
}