* Sanitize document ID for safe filesystem usage. * Replaces colons with underscores and validates no path traversal.
(id: string)
| 40 | * Replaces colons with underscores and validates no path traversal. |
| 41 | */ |
| 42 | function sanitizeId(id: string): string { |
| 43 | // Replace colons with underscores (e.g., "code:repos" -> "code_repos") |
| 44 | const sanitized = id.replace(/:/g, "_") |
| 45 | |
| 46 | // Validate no path traversal |
| 47 | if (sanitized.includes("..") || sanitized.includes("/") || sanitized.includes("\\")) { |
| 48 | throw new Error(`Invalid document ID: ${id}`) |
| 49 | } |
| 50 | |
| 51 | return sanitized |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Unsanitize document ID (convert back from filesystem name). |
no test coverage detected