chore: don't sanitize file extension away (#327)

This commit is contained in:
Simon Knott 2025-05-02 19:58:48 +02:00 committed by GitHub
parent 062cdd0704
commit 2c9376e50f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 5 deletions

View File

@ -70,6 +70,13 @@ export async function waitForCompletion<R>(context: Context, page: playwright.Pa
} }
} }
export function sanitizeForFilePath(s: string) { function sanitize(s: string) {
return s.replace(/[\x00-\x2C\x2E-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+/g, '-'); return s.replace(/[\x00-\x2C\x2E-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+/g, '-');
} }
export function sanitizeForFilePath(s: string) {
const separator = s.lastIndexOf('.');
if (separator === -1)
return sanitize(s);
return sanitize(s.substring(0, separator)) + '.' + sanitize(s.substring(separator + 1));
}

View File

@ -110,14 +110,14 @@ test('clicking on download link emits download', async ({ startClient }, testInf
url: 'data:text/html,<a href="data:text/plain,Hello world!" download="test.txt">Download</a>', url: 'data:text/html,<a href="data:text/plain,Hello world!" download="test.txt">Download</a>',
}, },
})).toContainTextContent('- link "Download" [ref=s1e3]'); })).toContainTextContent('- link "Download" [ref=s1e3]');
await client.callTool({
await expect.poll(() => client.callTool({
name: 'browser_click', name: 'browser_click',
arguments: { arguments: {
element: 'Download link', element: 'Download link',
ref: 's1e3', ref: 's1e3',
}, },
})).toContainTextContent(` });
### Downloads await expect.poll(() => client.callTool({ name: 'browser_snapshot', arguments: {} })).toContainTextContent(`
- Downloaded file test.txt to ${path.join(outputDir, 'test-txt')}`); ### Downloads
- Downloaded file test.txt to ${path.join(outputDir, 'test.txt')}`);
}); });