Skip to content

Commit

Permalink
Treat quote as value if already in quote using another delimiter
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego da Silva authored and michalbundyra committed Apr 1, 2020
1 parent d52d25b commit 64e1af1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
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());
}
}

0 comments on commit 64e1af1

Please sign in to comment.