@@ -123,6 +123,22 @@ private function createParameter(string $name, string $value): string
123
123
$ maxValueLength = $ this ->getMaxLineLength () - \strlen ($ name .'*N*=""; ' ) - 1 ;
124
124
$ firstLineOffset = \strlen ($ this ->getCharset ()."' " .$ this ->getLanguage ()."' " );
125
125
}
126
+
127
+ if (\in_array ($ name , ['name ' , 'filename ' ], true ) && 'form-data ' === $ this ->getValue () && 'content-disposition ' === strtolower ($ this ->getName ()) && preg_match ('//u ' , $ value )) {
128
+ // WHATWG HTML living standard 4.10.21.8 2 specifies:
129
+ // For field names and filenames for file fields, the result of the
130
+ // encoding in the previous bullet point must be escaped by replacing
131
+ // any 0x0A (LF) bytes with the byte sequence `%0A`, 0x0D (CR) with `%0D`
132
+ // and 0x22 (") with `%22`.
133
+ // The user agent must not perform any other escapes.
134
+ $ value = str_replace (['" ' , "\r" , "\n" ], ['%22 ' , '%0D ' , '%0A ' ], $ value );
135
+
136
+ if (\strlen ($ value ) <= $ maxValueLength ) {
137
+ return $ name .'=" ' .$ value .'" ' ;
138
+ }
139
+
140
+ $ value = $ origValue ;
141
+ }
126
142
}
127
143
128
144
// Encode if we need to
@@ -158,7 +174,7 @@ private function createParameter(string $name, string $value): string
158
174
*/
159
175
private function getEndOfParameterValue (string $ value , bool $ encoded = false , bool $ firstLine = false ): string
160
176
{
161
- $ forceHttpQuoting = 'content-disposition ' === strtolower ( $ this ->getName ()) && 'form-data ' === $ this ->getValue ( );
177
+ $ forceHttpQuoting = 'form-data ' === $ this ->getValue () && 'content-disposition ' === strtolower ( $ this ->getName () );
162
178
if ($ forceHttpQuoting || !preg_match ('/^ ' .self ::TOKEN_REGEX .'$/D ' , $ value )) {
163
179
$ value = '" ' .$ value .'" ' ;
164
180
}
0 commit comments