File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -439,10 +439,32 @@ export class Multipart implements Part {
439439 return Multipart . combineArrays ( result ) ;
440440 }
441441
442+ private static boundaryShouldBeQuoted ( boundary : Uint8Array ) : boolean {
443+ for ( const byte of boundary ) {
444+ if (
445+ byte === Multipart . HT
446+ || byte === Multipart . SP
447+ || byte === 0x22
448+ || byte === 0x28
449+ || byte === 0x29
450+ || byte === 0x2c
451+ || byte === 0x2f
452+ || ( byte >= Multipart . COLON && byte <= 0x40 )
453+ || ( byte >= 0x5b && byte <= 0x5d )
454+ || byte === 0x7b
455+ || byte === 0x7d
456+ ) return true ;
457+ }
458+ return false ;
459+ }
460+
442461 /**
443462 * Set the `Content-Type` header of this multipart based on {@link mediaType} and {@link boundary}.
444463 */
445464 private setHeaders ( ) {
446- this . headers . set ( "Content-Type" , this . #mediaType + "; boundary=" + new TextDecoder ( ) . decode ( this . #boundary) ) ;
465+ const shouldQuoteBoundary = Multipart . boundaryShouldBeQuoted ( this . #boundary) ;
466+ const boundaryString = new TextDecoder ( ) . decode ( this . #boundary) ;
467+ const boundary = shouldQuoteBoundary ? `"${ boundaryString . replace ( / " / g, '\\"' ) } "` : boundaryString ;
468+ this . headers . set ( "Content-Type" , this . #mediaType + "; boundary=" + boundary ) ;
447469 }
448470}
You can’t perform that action at this time.
0 commit comments