File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -159,6 +159,33 @@ describe("Multipart", function () {
159159 expect ( part3 . headers . get ( "x-foo" ) ) . to . equal ( "Foo" ) ;
160160 expect ( new TextDecoder ( ) . decode ( part3 . body ) ) . to . equal ( "The boundary delimiter of this part has trailing SP and tab." ) ;
161161 } ) ;
162+
163+ it ( "should handle strings that look like part boundary" , function ( ) {
164+ const string =
165+ '--simple boundary\r\n' +
166+ 'X-Foo: Bar\r\n' +
167+ '\r\n' +
168+ 'Can this handle\r\n' +
169+ '--simple boundary this is fake\r\n' +
170+ '\r\n' +
171+ 'not new part\r\n' +
172+ '--simple boundary\r\n' +
173+ 'X-Foo: Baz\r\n' +
174+ '\r\n' +
175+ 'Final part\r\n' +
176+ '--simple boundary--\r\n'
177+
178+ const parsedMultipart = Multipart . parseBody ( new TextEncoder ( ) . encode ( string ) , new TextEncoder ( ) . encode ( "simple boundary" ) ) ;
179+
180+ expect ( parsedMultipart ) . to . be . an . instanceof ( Multipart ) ;
181+ expect ( parsedMultipart . parts . length ) . to . equal ( 2 ) ;
182+ const part1 = parsedMultipart . parts [ 0 ] ;
183+ expect ( part1 . headers . get ( "x-foo" ) ) . to . equal ( "Bar" ) ;
184+ expect ( new TextDecoder ( ) . decode ( part1 . body ) ) . to . equal ( "Can this handle\r\n--simple boundary this is fake\r\n\r\nnot new part" ) ;
185+ const part2 = parsedMultipart . parts [ 1 ] ;
186+ expect ( part2 . headers . get ( "x-foo" ) ) . to . equal ( "Baz" ) ;
187+ expect ( new TextDecoder ( ) . decode ( part2 . body ) ) . to . equal ( "Final part" ) ;
188+ } ) ;
162189 } ) ;
163190
164191 describe ( "formData" , function ( ) {
You can’t perform that action at this time.
0 commit comments