Skip to content

Commit 0cd9b06

Browse files
authored
fix: only set extend notation on non-ascii filename (#558)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Enhanced filename handling to include UTF-8 encoding for non-ASCII filenames in content disposition. - **Bug Fixes** - Improved logic for constructing content disposition strings based on filename character set. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent b98b502 commit 0cd9b06

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/FormData.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import path from 'node:path';
22
import _FormData from 'form-data';
33

4+
// eslint-disable-next-line
5+
const NON_ASCII_RE = /[^\x00-\x7F]/i;
6+
47
export class FormData extends _FormData {
58
_getContentDisposition(value: any, options: any) {
69
// support non-ascii filename
@@ -24,7 +27,10 @@ export class FormData extends _FormData {
2427
if (filename) {
2528
// https://datatracker.ietf.org/doc/html/rfc6266#section-4.1
2629
// support non-ascii filename
27-
contentDisposition = 'filename="' + filename + '"; filename*=UTF-8\'\'' + encodeURIComponent(filename);
30+
contentDisposition = 'filename="' + filename + '"';
31+
if (NON_ASCII_RE.test(filename)) {
32+
contentDisposition += '; filename*=UTF-8\'\'' + encodeURIComponent(filename);
33+
}
2834
}
2935

3036
return contentDisposition;

0 commit comments

Comments
 (0)