File tree Expand file tree Collapse file tree 2 files changed +36
-2
lines changed
Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -86,11 +86,21 @@ function multipartFormDataParser (input, mimeType) {
8686 // the first byte.
8787 const position = { position : 0 }
8888
89- // Note: undici addition, allow \r\n before the body .
90- if ( input [ 0 ] === 0x0d && input [ 1 ] === 0x0a ) {
89+ // Note: undici addition, allows leading and trailing CRLFs .
90+ while ( input [ position . position ] === 0x0d && input [ position . position + 1 ] === 0x0a ) {
9191 position . position += 2
9292 }
9393
94+ let trailing = input . length
95+
96+ while ( input [ trailing - 1 ] === 0x0a && input [ trailing - 2 ] === 0x0d ) {
97+ trailing -= 2
98+ }
99+
100+ if ( trailing !== input . length ) {
101+ input = input . subarray ( 0 , trailing )
102+ }
103+
94104 // 5. While true:
95105 while ( true ) {
96106 // 5.1. If position points to a sequence of bytes starting with 0x2D 0x2D
Original file line number Diff line number Diff line change 1+ 'use strict'
2+
3+ const { test } = require ( 'node:test' )
4+ const assert = require ( 'node:assert' )
5+ const { Response } = require ( '../..' )
6+
7+ // https://github.com/nodejs/undici/issues/3676
8+ test ( 'Leading and trailing CRLFs are ignored' , async ( t ) => {
9+ const response = new Response ( [
10+ '--axios-1.7.7-boundary-bPgZ9x77LfApGVUN839vui4V7\r\n' +
11+ 'Content-Disposition: form-data; name="file"; filename="doc.txt"\r\n' +
12+ 'Content-Type: text/plain\r\n' +
13+ '\r\n' +
14+ 'Helloworld\r\n' +
15+ '--axios-1.7.7-boundary-bPgZ9x77LfApGVUN839vui4V7--\r\n' +
16+ '\r\n'
17+ ] . join ( '' ) , {
18+ headers : {
19+ 'content-type' : 'multipart/form-data; boundary=axios-1.7.7-boundary-bPgZ9x77LfApGVUN839vui4V7'
20+ }
21+ } )
22+
23+ await assert . doesNotReject ( response . formData ( ) )
24+ } )
You can’t perform that action at this time.
0 commit comments