Skip to content

Fix filename parsing for RFC 5987 Content-Disposition headers - #3492

Merged
beganovich merged 6 commits into
invoiceninja:developfrom
shrijayan:10189-content-disposition-filename
Nov 30, 2026
Merged

beganovich merged 6 commits into
invoiceninja:developfrom
shrijayan:10189-content-disposition-filename

Conversation

@shrijayan

@shrijayan shrijayan commented Nov 24, 2026 •

Copy link
Copy Markdown

Summary

The invoice PDF and e-invoice download hooks split the Content-Disposition header on filename=, so a header such as

attachment; filename=_0354.pdf; filename*=utf-8''%E8%AB%8B%E6%B1%82%E6%9B%B8_0354.pdf

produced 0354.pdf; filename*=utf-8''... as the download name. The shared helper also missed the lowercase utf-8'' that Symfony emits.

Change

  • src/common/helpers/download.ts
    • Make the filename* regex case-insensitive and tolerate whitespace around =.
  • src/pages/invoices/common/hooks/useDownloadPdf.ts
  • src/pages/invoices/common/hooks/useDownloadEInvoice.ts
    • Use the shared extractFilenameFromHeaders() and downloadBlob() helpers instead of splitting on filename= and hand-rolling the blob download.
  • tests/unit/helpers/download.test.ts
    • 11 cases, including the exact Japanese header, an RFC 5987 language tag, malformed percent-encoding, and the ASCII fallback.

Verification

 RUN  v4.1.10

 Test Files  1 passed (1)
      Tests  11 passed (11)

npx tsc --noEmit and npx biome check pass on the changed files.

Fixes invoiceninja/invoiceninja#10189.


This PR was prepared with AI assistance (Claude) and reviewed and tested locally. I am an open-source lover with a high token budget; if this is not the right approach, please reject it or improve it. Thanks for understanding.

@CLAassistant

CLAassistant commented Nov 24, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@beganovich
beganovich changed the base branch from main to develop November 30, 2026 10:21
shrijayan and others added 6 commits November 30, 2026 11:22
The invoice PDF and e-invoice download hooks split the header on
"filename=", so a header such as
  attachment; filename=_0354.pdf; filename*=utf-8''%E8%AB%8B...
produced "0354.pdf; filename*=utf-8''..." as the download name. Use
the shared extractFilenameFromHeaders() helper, and make its filename*
regex case-insensitive so the lowercase utf-8'' sent by Symfony is
decoded.

Fixes invoiceninja/invoiceninja#10189
Accept filename*=UTF-8'<lang>'<value> and return an empty string instead
of throwing when decodeURIComponent sees malformed percent-encoding.
A malformed percent-encoded filename* should not discard a valid ASCII
filename= fallback. Exclude filename* from the fallback regex so a
header without an ASCII name still returns an empty string.
Replace the duplicated blob/link/click sequence with downloadBlob(),
which also revokes the object URL.
@beganovich
beganovich force-pushed the 10189-content-disposition-filename branch from 8a23d75 to 559b9c1 Compare November 30, 2026 10:25
@beganovich
beganovich merged commit 33e36de into invoiceninja:develop Nov 30, 2026
2 checks passed
@beganovich

Copy link
Copy Markdown
Member

Thanks 👍

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error with Japanese localize

3 participants