Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/node/src/body.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,21 @@ describe('toNodeHttpBody', () => {
expect(generateContentDispositionSpy).toHaveBeenCalledWith('foo.pdf')
})

it('file with undefined name (Bun compatibility)', async () => {
// Bun returns `undefined` for an empty File name
const file = new File(['foo'], '', { type: 'application/pdf' })
Object.defineProperty(file, 'name', { value: undefined })

generateContentDispositionSpy.mockReturnValue('inline; filename="__mocked__"')

const [body, headers] = toNodeHttpBody(file, baseHeaders, {})

expect(body).toBeInstanceOf(Readable)
expect(headers['content-disposition']).toBe('inline; filename="__mocked__"')
expect(generateContentDispositionSpy).toHaveBeenCalledTimes(1)
expect(generateContentDispositionSpy).toHaveBeenCalledWith('')
})

it('event stream', async () => {
async function* gen() {
yield 123
Expand Down
3 changes: 2 additions & 1 deletion packages/node/src/body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ export function toNodeHttpBody(
headers['standard-server'] ??= 'file' satisfies StandardBodyHint // A File is also a Blob

headers['content-type'] = body.type
headers['content-disposition'] ??= generateContentDisposition(body instanceof File ? body.name : 'blob')
// FIX: Bun returns `undefined` for an empty File name, despite the spec requiring a string
headers['content-disposition'] ??= generateContentDisposition(body instanceof File ? body.name ?? '' : 'blob')

// BunS3 can use NaN for the size
if (Number.isFinite(body.size)) {
Expand Down
Loading