From fb1ec5ff3ff3f6c19813e88170f7640b286daf47 Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Sat, 7 Nov 2026 18:00:22 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A4=20fix:=20Encode=20Unicode=20Filena?= =?UTF-8?q?mes=20in=20Project=20File=20Uploads=20(#17878)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Encode Unicode Filenames in Project File Uploads Project uploads sent the raw filename, which multer reads as latin1 and the upload route then decodes with decodeURIComponent. Non-ASCII names were garbled, a stray percent sign failed with a 400, and a valid escape such as %20 was silently rewritten. Percent-encode the name the same way chat uploads do. * test: Cover Unicode and Percent Project Upload Filenames --- .../Projects/ProjectResources.spec.tsx | 14 ++++++ .../components/Projects/ProjectResources.tsx | 2 +- .../mock/scenarios/project-files-ui.spec.ts | 50 +++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/client/src/components/Projects/ProjectResources.spec.tsx b/client/src/components/Projects/ProjectResources.spec.tsx index 341ea4ba8c..6f45b42545 100644 --- a/client/src/components/Projects/ProjectResources.spec.tsx +++ b/client/src/components/Projects/ProjectResources.spec.tsx @@ -251,6 +251,20 @@ describe('ProjectResources', () => { ); }); + it.each(['Описание.md', '日本語.md', '100% done.md', 'a%20b.md'])( + 'percent-encodes the multipart filename of %s for the upload route to decode', + async (filename) => { + mockUploadMutateAsync.mockResolvedValue(uploadedFile); + renderResources(); + fireEvent.change(screen.getByTestId('project-upload-input'), { + target: { files: [new File(['x'], filename)] }, + }); + await waitFor(() => expect(mockUploadMutateAsync).toHaveBeenCalledTimes(1)); + const formData = mockUploadMutateAsync.mock.calls[0][0] as FormData; + expect((formData.get('file') as File).name).toBe(encodeURIComponent(filename)); + }, + ); + it('retries a failed association without uploading another binary', async () => { mockUploadMutateAsync.mockResolvedValue(uploadedFile); mockAddMutateAsync.mockRejectedValueOnce({ diff --git a/client/src/components/Projects/ProjectResources.tsx b/client/src/components/Projects/ProjectResources.tsx index fdbe69bf74..db47f07fa1 100644 --- a/client/src/components/Projects/ProjectResources.tsx +++ b/client/src/components/Projects/ProjectResources.tsx @@ -259,7 +259,7 @@ export default function ProjectResources({ project }: ProjectResourcesProps) { let fileId = item.fileId; if (!fileId) { const formData = new FormData(); - formData.append('file', item.file); + formData.append('file', item.file, encodeURIComponent(item.file.name)); formData.append('file_id', item.id); formData.append('endpoint', 'agents'); formData.append('message_file', 'true'); diff --git a/e2e/specs/mock/scenarios/project-files-ui.spec.ts b/e2e/specs/mock/scenarios/project-files-ui.spec.ts index 10c068dc52..45874cf0e2 100644 --- a/e2e/specs/mock/scenarios/project-files-ui.spec.ts +++ b/e2e/specs/mock/scenarios/project-files-ui.spec.ts @@ -187,6 +187,38 @@ async function uploadFromDevice(page: Page, files: Array<{ name: string; content return uploadResponse; } +/** Reloads before asserting so the row shows the stored name, not the browser's local File. */ +async function expectUploadStoredAs( + page: Page, + request: APIRequestContext, + sentName: string, + storedName: string, +): Promise { + let projectId: string | undefined; + const fileIds: string[] = []; + try { + await enableProjectFiles(page); + projectId = await createProject(page, uniqueName('Filename project')); + await page.reload({ waitUntil: 'domcontentloaded' }); + + const uploadResponse = await uploadFromDevice(page, [ + { name: sentName, content: 'project file with a non-trivial name' }, + ]); + expect(uploadResponse.ok()).toBeTruthy(); + const uploaded = (await uploadResponse.json()) as UploadedFile; + if (uploaded.file_id) { + fileIds.push(uploaded.file_id); + } + + const row = page.getByRole('listitem').filter({ hasText: storedName }); + await expect(row).toContainText('Ready', { timeout: 30000 }); + await page.reload({ waitUntil: 'domcontentloaded' }); + await expect(row).toContainText('Ready', { timeout: 30000 }); + } finally { + await cleanupProjectAndFiles(page, request, projectId, fileIds, [storedName]); + } +} + test.describe('project file workspace UI', () => { test('selecting several files at once queues every file up to the project limit and reports the excess @scenario:multi-file-upload-queues-to-capacity-and-reports-excess', async ({ page, @@ -406,4 +438,22 @@ test.describe('project file workspace UI', () => { await cleanupProjectAndFiles(page, request, projectId, fileIds, filenames); } }); + + test('a project file with a non-Latin name keeps that name after upload @scenario:project-upload-keeps-non-latin-filename', async ({ + page, + request, + }) => { + test.setTimeout(120000); + const name = `Описание-日本語-${randomUUID().slice(0, 8)}.txt`; + await expectUploadStoredAs(page, request, name, name); + }); + + test('a project file with a percent sign in its name uploads instead of being rejected @scenario:project-upload-accepts-percent-filename', async ({ + page, + request, + }) => { + test.setTimeout(120000); + const stem = randomUUID().slice(0, 8); + await expectUploadStoredAs(page, request, `100% ${stem}.txt`, `100__${stem}.txt`); + }); });