chore: sanitize file path when saving (#99)
Fixes https://github.com/microsoft/playwright-mcp/issues/96
This commit is contained in:
@@ -20,7 +20,7 @@ import path from 'path';
|
||||
import { z } from 'zod';
|
||||
import { zodToJsonSchema } from 'zod-to-json-schema';
|
||||
|
||||
import { captureAriaSnapshot, runAndWait } from './utils';
|
||||
import { captureAriaSnapshot, runAndWait, sanitizeForFilePath } from './utils';
|
||||
|
||||
import type { ToolFactory, Tool } from './tool';
|
||||
|
||||
@@ -127,7 +127,7 @@ export const pdf: Tool = {
|
||||
},
|
||||
handle: async context => {
|
||||
const page = context.existingPage();
|
||||
const fileName = path.join(os.tmpdir(), `/page-${new Date().toISOString()}.pdf`);
|
||||
const fileName = path.join(os.tmpdir(), sanitizeForFilePath(`page-${new Date().toISOString()}`)) + '.pdf';
|
||||
await page.pdf({ path: fileName });
|
||||
return {
|
||||
content: [{
|
||||
|
||||
@@ -106,3 +106,7 @@ export async function captureAriaSnapshot(context: Context, status: string = '')
|
||||
content: [{ type: 'text', text: lines.join('\n') }],
|
||||
};
|
||||
}
|
||||
|
||||
export function sanitizeForFilePath(s: string) {
|
||||
return s.replace(/[\x00-\x2C\x2E-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+/g, '-');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user