MCPcopy Create free account
hub / github.com/bearlyai/OpenADE / sanitizeId

Function sanitizeId

projects/electron/src/modules/code/yjsStorage.ts:42–52  ·  view source on GitHub ↗

* Sanitize document ID for safe filesystem usage. * Replaces colons with underscores and validates no path traversal.

(id: string)

Source from the content-addressed store, hash-verified

40 * Replaces colons with underscores and validates no path traversal.
41 */
42function 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).

Callers 2

getDocPathFunction · 0.70
getLegacyNestedDocPathFunction · 0.70

Calls 1

replaceMethod · 0.80

Tested by

no test coverage detected