Skip to content

Upgrade content-disposition#7233

Merged
bjohansebas merged 5 commits into
masterfrom
be/upgrade-content-disposition
Jun 16, 2026
Merged

Upgrade content-disposition#7233
bjohansebas merged 5 commits into
masterfrom
be/upgrade-content-disposition

Conversation

@blakeembrey

Copy link
Copy Markdown
Member

Version 2 upgrade will mostly only be relevant for users that want to generate non-ASCII by ISO-8859-1 valid filenames. There was a gap in theoretical vs real behavior of browsers that sniffed this and failed to have the correct encoding for filenames because it treated them as UTF-8 instead. See jshttp/content-disposition#27 for more information.

Separately, the API no longer attempts to basename inputs so I need to do that in the Express API instead.

@blakeembrey blakeembrey requested a review from a team May 11, 2026 21:08
@socket-security

socket-security Bot commented May 11, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednpm/​content-disposition@​2.0.110010010091100

View full report

Comment thread lib/response.js Outdated
// set Content-Disposition when file is sent
var headers = {
'Content-Disposition': contentDisposition(name || path)
'Content-Disposition': contentDisposition.create(name || basename(path))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The correct backward compatibility would be basename(name || path), should I do that instead? The difference is if someone gave a path instead of a filename in the filename parameter.

@bjohansebas bjohansebas force-pushed the be/upgrade-content-disposition branch from 5b1dd33 to 2d0d3c5 Compare June 15, 2026 19:58
@bjohansebas

Copy link
Copy Markdown
Member

Content-Disposition: old (v1.1.0) vs new (v2.0.1)

Express output for the tests added in test/res.attachment.js. All outputs are
RFC 6266 / 8187 / 9110 compliant.

Express call Old (v1.1.0) New (v2.0.1) Changed?
res.attachment('/path/to/my report.png') attachment; filename="my report.png" attachment; filename="my report.png" No
res.attachment('/locales/café.txt') attachment; filename="café.txt" attachment; filename="caf?.txt"; filename*=UTF-8''caf%C3%A9.txt Yes
res.attachment('') attachment; filename*=UTF-8'' attachment; filename="" Yes

Notes

  • Space in name: still quoted in both, a non-token value must be a quoted-string.
  • Latin1 name: v2 emits an ASCII fallback (filename) plus the UTF-8 filename*
    extended form, instead of putting the raw non-ASCII byte in filename — more
    interoperable and spec-clean.
  • Empty name: both valid; v2 uses an empty quoted-string, v1 an empty filename*.

@bjohansebas bjohansebas force-pushed the be/upgrade-content-disposition branch from 21c7e27 to 754a183 Compare June 16, 2026 02:42
@bjohansebas bjohansebas merged commit 59e205a into master Jun 16, 2026
30 checks passed
@bjohansebas bjohansebas deleted the be/upgrade-content-disposition branch June 16, 2026 02:45
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.

2 participants