-
Notifications
You must be signed in to change notification settings - Fork 111
Conversation
@weierophinney any chance to take a look? thanks! |
@rodnaph Please rebase off of current master, and then look at https://github.com/zendframework/zend-mail/blob/79f0f72fbaf606f4a2db322bb2fe2e381d2e9d53/src/Header/AddressListParser.php — this class provides a parser for address list items currently, and I think the approach it presents (a proper parser) is likely a better fit for the fix you're trying to implement. (Also, run |
@weierophinney Thanks - the parser class works for this case if you can allow a minor customisation (though the name is now perhaps a little misleading if it's used in both locations). |
src/Header/AddressListParser.php
Outdated
* @return array | ||
*/ | ||
public static function parse($value) | ||
public static function parse($value, $delims = self::CHAR_DELIMS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
array type hint?
The purpose of the class is to parse a string into a list of values, splitting on a set of delimiters.
Since the |
@@ -42,6 +42,10 @@ All notable changes to this project will be documented in this file, in reverse | |||
|
|||
### Fixed | |||
|
|||
- [#211](https://github.com/zendframework/zend-mail/pull/211) fixes how the `ContentType` header class parses the value it receives. Previously, | |||
it was incorrectly splitting the value on semi-colons that were inside quotes; in now correctly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it now correctly ignores them.
When parsing the
Content-Type
header there is an assumption that the type and key/value pairs can be split by semi-colon, but this is incorrect when a value contains a semi-colon (eg.name="foo; bar"
). This format is covered by the RFC (https://tools.ietf.org/html/rfc2045#page-12,Must be in quoted-string to use within parameter values
), and is seen in data in the wild. This patch adds support for this.Currently an exception is thrown in strict mode because of an undefined offset (
Undefined offset: 1
). I've updated the code to useparse_str
to better handle this data, which I think is an improvement over the regexp splitting, but still not ideal without a proper lexer/tokenizer obv.I've also enabled strict mode for PHPUnit by default to expose these kinds of bugs in the test suite.