@@ -5,6 +5,7 @@ import { isMultipartError, type MultipartError, readMultipart } from '@/lib/core
55type Part =
66 | { name : string ; value : string }
77 | { name : string ; filename : string ; value : string ; contentType ?: string }
8+ | { name : string ; value : string ; contentType : string }
89
910const BOUNDARY = '----testboundary1234'
1011
@@ -14,6 +15,8 @@ function buildBody(parts: Part[], boundary = BOUNDARY): Buffer {
1415 let header = `--${ boundary } \r\nContent-Disposition: form-data; name="${ part . name } "`
1516 if ( 'filename' in part ) {
1617 header += `; filename="${ part . filename } "\r\nContent-Type: ${ part . contentType ?? 'text/csv' } `
18+ } else if ( 'contentType' in part ) {
19+ header += `\r\nContent-Type: ${ part . contentType } `
1720 }
1821 header += '\r\n\r\n'
1922 segments . push ( Buffer . from ( header , 'utf8' ) , Buffer . from ( part . value , 'utf8' ) , Buffer . from ( '\r\n' ) )
@@ -121,6 +124,18 @@ describe('readMultipart', () => {
121124 )
122125 } )
123126
127+ it ( 'rejects NO_FILE when the file part carries no filename' , async ( ) => {
128+ const request = makeRequest ( [
129+ { name : 'file' , value : 'name\nAlice\n' , contentType : 'application/octet-stream' } ,
130+ ] )
131+ await readMultipart ( request , { maxFileBytes : 1024 } ) . then (
132+ ( ) => {
133+ throw new Error ( 'expected rejection' )
134+ } ,
135+ ( err ) => expectCode ( err , 'NO_FILE' )
136+ )
137+ } )
138+
124139 it ( 'rejects NOT_MULTIPART for a non-multipart content type' , async ( ) => {
125140 const request = {
126141 headers : new Headers ( { 'content-type' : 'application/json' } ) ,
0 commit comments