Skip to content

Commit 747a8ee

Browse files
kadamwhiteclaude
andcommitted
fetch-transport: don't pass an undefined filename to FormData.append
Fixes the Node 22 CI failure (present on main since the Phase 2 merge -- the Node 22 leg has been red, masked locally by developing on Node 24). FormData coerces an explicitly-passed undefined filename argument to the string 'undefined' on Node 18-22, clobbering a File attachment's own name; Node 24+ treats a trailing undefined as absent. Omit the argument entirely when no name override exists, which is what the adjacent comment always claimed the code did. Verified: transport unit suite 20/20 under Node 22.14 (was 19/20), full 599 unit suite and the media-upload integration suite green on Node 24. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent fff9fce commit 747a8ee

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

fetch/fetch-transport.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,18 @@ const createUploadForm = async (
205205
}
206206

207207
const form = new FormData();
208-
// An undefined name is treated as omitted: File attachments keep their own name.
208+
// An undefined name must be genuinely omitted, not passed as an explicit third
209+
// argument: FormData coerces a present-but-undefined filename to the string
210+
// "undefined" on Node 18-22, clobbering a File attachment's own name. (Node 24+
211+
// treats a trailing undefined as absent, which masked this in local dev.)
209212
// Cast: by this point `file` is always a Blob at runtime (the `string` and
210213
// `Buffer` cases above always reassign it to one), but TS can't prove the
211214
// `globalThis.Buffer &&`-guarded branch always narrows away `Buffer`.
212-
form.append( 'file', file as Blob, name );
215+
if ( name === undefined ) {
216+
form.append( 'file', file as Blob );
217+
} else {
218+
form.append( 'file', file as Blob, name );
219+
}
213220
// Cast: form field values are arbitrary caller-supplied data, but FormData's
214221
// global (DOM) typing only accepts strings or Blobs.
215222
Object.keys( data ).forEach( key => form.append( key, data[ key ] as string | Blob ) );

0 commit comments

Comments
 (0)