diff --git a/src/tools/utils.ts b/src/tools/utils.ts index 5142bad..16a35b9 100644 --- a/src/tools/utils.ts +++ b/src/tools/utils.ts @@ -70,6 +70,13 @@ export async function waitForCompletion(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, '-'); } + +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)); +} diff --git a/tests/files.spec.ts b/tests/files.spec.ts index 10f6b8c..8951f6f 100644 --- a/tests/files.spec.ts +++ b/tests/files.spec.ts @@ -110,14 +110,14 @@ test('clicking on download link emits download', async ({ startClient }, testInf url: 'data:text/html,Download', }, })).toContainTextContent('- link "Download" [ref=s1e3]'); - - await expect.poll(() => client.callTool({ + await client.callTool({ name: 'browser_click', arguments: { element: 'Download link', ref: 's1e3', }, - })).toContainTextContent(` + }); + await expect.poll(() => client.callTool({ name: 'browser_snapshot', arguments: {} })).toContainTextContent(` ### Downloads -- Downloaded file test.txt to ${path.join(outputDir, 'test-txt')}`); +- Downloaded file test.txt to ${path.join(outputDir, 'test.txt')}`); });