MCPcopy Index your code
hub / github.com/coder/mux / sanitizeStorageKey

Function sanitizeStorageKey

src/node/services/workspaceProjectRepos.ts:43–70  ·  view source on GitHub ↗
(projectName: string, projectPath: string)

Source from the content-addressed store, hash-verified

41}
42
43function sanitizeStorageKey(projectName: string, projectPath: string): string {
44 const sanitize = (value: string) =>
45 value
46 .split("")
47 .map((char) => {
48 const isForbiddenPathChar = '<>:"/\\|?*'.includes(char);
49 return isForbiddenPathChar || char.charCodeAt(0) < 32 ? "-" : char;
50 })
51 .join("")
52 .trim();
53
54 const sanitizedProjectName = sanitize(projectName);
55 const fallbackProjectName =
56 sanitize(PlatformPaths.getProjectName(projectPath).trim()) || "project";
57 const storageKey =
58 sanitizedProjectName.length > 0 && sanitizedProjectName !== "." && sanitizedProjectName !== ".."
59 ? sanitizedProjectName
60 : fallbackProjectName;
61
62 assert(!path.isAbsolute(storageKey), "getWorkspaceProjectRepos: storageKey must stay relative");
63 assert(
64 !storageKey.includes(path.sep) && !storageKey.includes(path.posix.sep),
65 "getWorkspaceProjectRepos: storageKey must not contain path separators"
66 );
67 assert(storageKey !== "." && storageKey !== "..", "getWorkspaceProjectRepos: invalid storageKey");
68
69 return storageKey;
70}
71
72function appendStorageKeySuffix(storageKey: string, suffix: number): string {
73 assert(Number.isInteger(suffix) && suffix >= 2, "appendStorageKeySuffix: suffix must be >= 2");

Callers 1

Calls 4

sanitizeFunction · 0.85
isAbsoluteMethod · 0.80
assertFunction · 0.50
getProjectNameMethod · 0.45

Tested by

no test coverage detected