Skip to content

Commit

Permalink
fix: only set extend notation on non-ascii filename (#558)
Browse files Browse the repository at this point in the history
<!-- 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 -->
  • Loading branch information
fengmk2 authored Dec 5, 2024
1 parent b98b502 commit 0cd9b06
Showing 1 changed file with 7 additions and 1 deletion.
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

0 comments on commit 0cd9b06

Please sign in to comment.