(projectName: string, projectPath: string)
| 41 | } |
| 42 | |
| 43 | function 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 | |
| 72 | function appendStorageKeySuffix(storageKey: string, suffix: number): string { |
| 73 | assert(Number.isInteger(suffix) && suffix >= 2, "appendStorageKeySuffix: suffix must be >= 2"); |
no test coverage detected