Skip to content

Commit b84fdf5

Browse files
Artur-claude
andauthored
fix: encode X-Filename header for files with special characters (#10451)
The X-Filename header now uses encodeURIComponent() to properly encode filenames containing non-ASCII characters (e.g., "religion åk4.pdf"). This prevents HTTP header encoding errors when uploading files with special characters in their names. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent 5fe3f38 commit b84fdf5

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

packages/upload/src/vaadin-upload-mixin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ export const UploadMixin = (superClass) =>
664664
// Set Content-Type and filename header for raw binary uploads
665665
if (isRawUpload && file) {
666666
xhr.setRequestHeader('Content-Type', file.type || 'application/octet-stream');
667-
xhr.setRequestHeader('X-Filename', file.name);
667+
xhr.setRequestHeader('X-Filename', encodeURIComponent(file.name));
668668
}
669669

670670
if (this.timeout) {

packages/upload/test/upload.test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,19 @@ describe('upload', () => {
593593
upload.uploadFormat = 'raw';
594594
upload.addEventListener('upload-request', (e) => {
595595
const filename = e.detail.xhr.getRequestHeader('X-Filename');
596-
expect(filename).to.equal(testFile.name);
596+
expect(filename).to.equal(encodeURIComponent(testFile.name));
597+
done();
598+
});
599+
upload._uploadFile(testFile);
600+
});
601+
602+
it('should encode special characters in X-Filename header in raw format', (done) => {
603+
const testFile = createFile(1000, 'application/pdf');
604+
testFile.name = 'religion åk4.pdf';
605+
upload.uploadFormat = 'raw';
606+
upload.addEventListener('upload-request', (e) => {
607+
const filename = e.detail.xhr.getRequestHeader('X-Filename');
608+
expect(filename).to.equal('religion%20%C3%A5k4.pdf');
597609
done();
598610
});
599611
upload._uploadFile(testFile);

0 commit comments

Comments
 (0)