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)
|
if (!attachment)
|
||||||
return;
|
return;
|
||||||
const headers = new Headers();
|
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)
|
if (attachment.contentType)
|
||||||
headers.set('Content-Type', attachment.contentType);
|
headers.set('Content-Type', attachment.contentType);
|
||||||
return headers;
|
return headers;
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ test('should contain text attachment', async ({ runUITest }) => {
|
||||||
import { test } from '@playwright/test';
|
import { test } from '@playwright/test';
|
||||||
test('attach test', async () => {
|
test('attach test', async () => {
|
||||||
await test.info().attach('note', { path: __filename });
|
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 page.getByTitle('Run all').click();
|
||||||
await expect(page.getByTestId('status-line')).toHaveText('1/1 passed (100%)');
|
await expect(page.getByTestId('status-line')).toHaveText('1/1 passed (100%)');
|
||||||
await page.getByText('Attachments').click();
|
await page.getByText('Attachments').click();
|
||||||
await page.getByText('attach "note"', { exact: true }).click();
|
for (const { name, content } of [
|
||||||
const downloadPromise = page.waitForEvent('download');
|
{ name: 'note', content: 'attach test' },
|
||||||
await page.getByRole('link', { name: 'note' }).click();
|
{ name: '🎭', content: 'hi tester!' }
|
||||||
const download = await downloadPromise;
|
]) {
|
||||||
expect(download.suggestedFilename()).toBe('note');
|
await page.getByText(`attach "${name}"`, { exact: true }).click();
|
||||||
expect((await readAllFromStream(await download.createReadStream())).toString()).toContain('attach test');
|
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 }) => {
|
test('should contain binary attachment', async ({ runUITest }) => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue