Skip to content

fix(files): encode apostrophes and parentheses in PDF filenames - #237

Open
chuiwenwei wants to merge 1 commit into
CopilotKit:mainfrom
chuiwenwei:fix/file-disposition-encoding
Open

chuiwenwei wants to merge 1 commit into
CopilotKit:mainfrom
chuiwenwei:fix/file-disposition-encoding

Conversation

@chuiwenwei

Copy link
Copy Markdown

What changed

The inline PDF response wrote filename*=UTF-8''${encodeURIComponent(name)}. encodeURIComponent leaves ', (, ) and * unescaped. Those are not RFC 5987 attr-chars, and the apostrophe is the value delimiter, so a name like O'Brien (final).pdf produced a malformed Content-Disposition.

The route now uses encodeDispositionName, which applies the same extra escaping the Gmail attachment encoder already uses.

Verification

  • pnpm lint
  • pnpm typecheck
  • pnpm --dir apps/worker typecheck
  • pnpm build:server
  • pnpm test — 526 passing

New tests/file-disposition.test.ts covers an apostrophe/parenthesis name, a plain name, and a non-ASCII name.

Integration limits

None.

The inline Content-Disposition value used encodeURIComponent, which leaves
"'", "(", ")" and "*" unescaped. Those are not RFC 5987 attr-chars, and an
apostrophe is the value delimiter in filename*=UTF-8''..., so a name like
"O'Brien (final).pdf" produced a malformed header.

Use the same attr-char escaping the attachment encoder already applies, and
cover ASCII, punctuation and non-ASCII names.

This branch has not been deployed

No deployments
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.

1 participant