(lang: string | undefined)
| 60 | return texts; |
| 61 | } |
| 62 | export function fileExtension(lang: string | undefined): string { |
| 63 | if (lang) { |
| 64 | // Sanitize to prevent path traversal (e.g. ```../../etc/passwd) |
| 65 | // Language identifiers are alphanumeric: python, tsx, jsonc, etc. |
| 66 | const sanitized = lang.replace(/[^a-zA-Z0-9]/g, ''); |
| 67 | if (sanitized && sanitized !== 'plaintext') { |
| 68 | return `.${sanitized}`; |
| 69 | } |
| 70 | } |
| 71 | return '.txt'; |
| 72 | } |
| 73 | async function writeToFile(text: string, filename: string): Promise<string> { |
| 74 | const filePath = join(COPY_DIR, filename); |
| 75 | await mkdir(COPY_DIR, { |
no outgoing calls
no test coverage detected