fix(trace-viewer): encode attachment filenames as UTF-8
This commit is contained in:
parent
306db80d03
commit
48ba6e3860
|
|
@ -159,7 +159,8 @@ function downloadHeadersForAttachment(traceModel: TraceModel, sha1: string): Hea
|
|||
if (!attachment)
|
||||
return;
|
||||
const headers = new Headers();
|
||||
headers.set('Content-Disposition', `attachment; filename="${attachment.name}"`);
|
||||
// Escape non-ascii characters and quotes.
|
||||
headers.set('Content-Disposition', `attachment; filename="attachment"; filename*=UTF-8''${encodeURIComponent(attachment.name)}`);
|
||||
if (attachment.contentType)
|
||||
headers.set('Content-Type', attachment.contentType);
|
||||
return headers;
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ test('should contain text attachment', async ({ runUITest }) => {
|
|||
import { test } from '@playwright/test';
|
||||
test('attach test', async () => {
|
||||
await test.info().attach('note', { path: __filename });
|
||||
await test.info().attach('🎭', { body: 'hi tester!', contentType: 'text/plain' });
|
||||
});
|
||||
`,
|
||||
});
|
||||
|
|
@ -31,12 +32,17 @@ test('should contain text attachment', async ({ runUITest }) => {
|
|||
await page.getByTitle('Run all').click();
|
||||
await expect(page.getByTestId('status-line')).toHaveText('1/1 passed (100%)');
|
||||
await page.getByText('Attachments').click();
|
||||
await page.getByText('attach "note"', { exact: true }).click();
|
||||
const downloadPromise = page.waitForEvent('download');
|
||||
await page.getByRole('link', { name: 'note' }).click();
|
||||
const download = await downloadPromise;
|
||||
expect(download.suggestedFilename()).toBe('note');
|
||||
expect((await readAllFromStream(await download.createReadStream())).toString()).toContain('attach test');
|
||||
for (const { name, content } of [
|
||||
{ name: 'note', content: 'attach test' },
|
||||
{ name: '🎭', content: 'hi tester!' }
|
||||
]) {
|
||||
await page.getByText(`attach "${name}"`, { exact: true }).click();
|
||||
const downloadPromise = page.waitForEvent('download');
|
||||
await page.getByRole('link', { name: name }).click();
|
||||
const download = await downloadPromise;
|
||||
expect(download.suggestedFilename()).toBe(name);
|
||||
expect((await readAllFromStream(await download.createReadStream())).toString()).toContain(content);
|
||||
}
|
||||
});
|
||||
|
||||
test('should contain binary attachment', async ({ runUITest }) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue