This repository was archived by the owner on Jan 30, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +45
-13
lines changed Expand file tree Collapse file tree 6 files changed +45
-13
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,10 @@ All notable changes to this project will be documented in this file, in reverse
42
42
43
43
### Fixed
44
44
45
+ - [ #211 ] ( https://github.com/zendframework/zend-mail/pull/211 ) fixes how the ` ContentType ` header class parses the value it receives. Previously,
46
+ it was incorrectly splitting the value on semi-colons that were inside quotes; in now correctly
47
+ ignores them.
48
+
45
49
- [ #204 ] ( https://github.com/zendframework/zend-mail/pull/204 ) fixes ` HeaderWrap::mimeDecodeValue() ` behavior when handling a multiline UTF-8
46
50
header split across a character. The fix will only work when ext-imap is present, however.
47
51
Original file line number Diff line number Diff line change 23
23
24
24
<php >
25
25
<ini name =" date.timezone" value =" UTC" />
26
+ <ini name =" error_reporting" value =" -1" />
26
27
27
28
<!-- OB_ENABLED should be enabled for some tests to check if all
28
29
functionality works as expected. Such tests include those for
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ public static function fromString($headerLine)
58
58
// split value on ","
59
59
$ fieldValue = str_replace (Headers::FOLDING , ' ' , $ fieldValue );
60
60
$ fieldValue = preg_replace ('/[^:]+:([^;]*);/ ' , '$1, ' , $ fieldValue );
61
- $ values = AddressListParser ::parse ($ fieldValue );
61
+ $ values = ListParser ::parse ($ fieldValue );
62
62
63
63
$ wasEncoded = false ;
64
64
$ addresses = array_map (
Original file line number Diff line number Diff line change @@ -40,19 +40,20 @@ public static function fromString($headerLine)
40
40
}
41
41
42
42
$ value = str_replace (Headers::FOLDING , ' ' , $ value );
43
- $ values = preg_split ( ' #\s*;\s*# ' , $ value );
43
+ $ parts = explode ( ' ; ' , $ value, 2 );
44
44
45
- $ type = array_shift ($ values );
46
45
$ header = new static ();
47
- $ header ->setType ($ type );
46
+ $ header ->setType ($ parts [ 0 ] );
48
47
49
- // Remove empty values
50
- $ values = array_filter ($ values );
48
+ if (isset ($ parts [1 ])) {
49
+ $ values = ListParser::parse (trim ($ parts [1 ]), ['; ' , '= ' ]);
50
+ $ length = count ($ values );
51
51
52
- foreach ($ values as $ keyValuePair ) {
53
- list ($ key , $ value ) = explode ('= ' , $ keyValuePair , 2 );
54
- $ value = trim ($ value , "' \" \t\n\r\0\x0B" );
55
- $ header ->addParameter ($ key , $ value );
52
+ for ($ i = 0 ; $ i < $ length ; $ i += 2 ) {
53
+ $ value = $ values [$ i + 1 ];
54
+ $ value = trim ($ value , "' \" \t\n\r\0\x0B" );
55
+ $ header ->addParameter ($ values [$ i ], $ value );
56
+ }
56
57
}
57
58
58
59
return $ header ;
Original file line number Diff line number Diff line change 9
9
10
10
use function in_array ;
11
11
12
- class AddressListParser
12
+ class ListParser
13
13
{
14
14
const CHAR_QUOTES = ['\'' , '" ' ];
15
15
const CHAR_DELIMS = [', ' , '; ' ];
16
16
const CHAR_ESCAPE = '\\' ;
17
17
18
18
/**
19
19
* @param string $value
20
+ * @param array $delims Delimiters allowed between values; parser will
21
+ * split on these, as long as they are not within quotes. Defaults
22
+ * to ListParser::CHAR_DELIMS.
20
23
* @return array
21
24
*/
22
- public static function parse ($ value )
25
+ public static function parse ($ value, array $ delims = self :: CHAR_DELIMS )
23
26
{
24
27
$ values = [];
25
28
$ length = strlen ($ value );
@@ -40,7 +43,7 @@ public static function parse($value)
40
43
41
44
// If we are not in a quoted string, and have a delimiter, append
42
45
// the current value to the list, and reset the current value.
43
- if (in_array ($ char , self :: CHAR_DELIMS , true ) && ! $ inQuote ) {
46
+ if (in_array ($ char , $ delims , true ) && ! $ inQuote ) {
44
47
$ values [] = $ currentValue ;
45
48
$ currentValue = '' ;
46
49
continue ;
Original file line number Diff line number Diff line change @@ -45,6 +45,29 @@ public function testExtractsExtraInformationWithoutBeingConfusedByTrailingSemico
45
45
$ this ->assertEquals ($ header ->getParameters (), ['name ' => 'foo.pdf ' ]);
46
46
}
47
47
48
+ public static function getLiteralData ()
49
+ {
50
+ return [
51
+ [
52
+ ['name ' => 'foo; bar.txt ' ],
53
+ 'text/plain; name="foo; bar.txt" '
54
+ ],
55
+ [
56
+ ['name ' => 'foo&bar.txt ' ],
57
+ 'text/plain; name="foo&bar.txt" '
58
+ ],
59
+ ];
60
+ }
61
+
62
+ /**
63
+ * @dataProvider getLiteralData
64
+ */
65
+ public function testHandlesLiterals (array $ expected , $ header )
66
+ {
67
+ $ header = ContentType::fromString ('Content-Type: ' .$ header );
68
+ $ this ->assertEquals ($ expected , $ header ->getParameters ());
69
+ }
70
+
48
71
/**
49
72
* @dataProvider setTypeProvider
50
73
*/
You can’t perform that action at this time.
0 commit comments