Skip to content

fix: keep the Content-Disposition filename ASCII for non-ASCII file names - #237

Open
RaphaelFakhri wants to merge 1 commit into
vercel:mainfrom
RaphaelFakhri:fix-content-disposition-non-ascii
Open

RaphaelFakhri wants to merge 1 commit into
vercel:mainfrom
RaphaelFakhri:fix-content-disposition-non-ascii

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Fixes #205. Files with non-ASCII names such as brasão.txt or DALL·E.png fail with ERR_INVALID_CHAR and the request never gets a valid response.

Problem

content-disposition keeps ISO-8859-1 characters in the plain filename parameter. Node.js rejects the header when the response also sets Content-Length, so writeHead() throws ERR_INVALID_CHAR for the Content-Disposition header.

Changes

  • Passes an ASCII-only fallback to contentDisposition(). Non-ASCII characters in the plain filename parameter become ?, and the full name is sent in filename* (RFC 5987). ASCII names produce the same header as before.
  • Adds an integration test that serves files named with Latin-1, a middle dot, and CJK characters.

Testing

yarn run build-views && npx jest --forceExit test/integration.test.js

Before the change, the new test fails with status 500 and the other 70 tests pass. After the change, all 71 tests pass and zeit-eslint is clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problems with UTF characters

1 participant