Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only set extend notation on non-ascii filename #558

Merged
merged 2 commits into from
Dec 5, 2024
Merged
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
8 changes: 7 additions & 1 deletion src/FormData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import path from 'node:path';
import _FormData from 'form-data';

// eslint-disable-next-line
const NON_ASCII_RE = /[^\x00-\x7F]/i;

export class FormData extends _FormData {
_getContentDisposition(value: any, options: any) {
// support non-ascii filename
Expand All @@ -24,7 +27,10 @@ export class FormData extends _FormData {
if (filename) {
// https://datatracker.ietf.org/doc/html/rfc6266#section-4.1
// support non-ascii filename
contentDisposition = 'filename="' + filename + '"; filename*=UTF-8\'\'' + encodeURIComponent(filename);
contentDisposition = 'filename="' + filename + '"';
if (NON_ASCII_RE.test(filename)) {
contentDisposition += '; filename*=UTF-8\'\'' + encodeURIComponent(filename);
}
}

return contentDisposition;
Expand Down
Loading