fix(app): sanitize workspace store filenames on Windows (#16703)
This commit is contained in:
parent
34328828ae
commit
f27ef595f6
3 changed files with 11 additions and 2 deletions
|
|
@ -57,7 +57,7 @@ export function sessionPath(directory: string, sessionID?: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function workspacePersistKey(directory: string, key: string) {
|
export function workspacePersistKey(directory: string, key: string) {
|
||||||
const head = directory.slice(0, 12) || "workspace"
|
const head = (directory.slice(0, 12) || "workspace").replace(/[^a-zA-Z0-9._-]/g, "-")
|
||||||
const sum = checksum(directory) ?? "0"
|
const sum = checksum(directory) ?? "0"
|
||||||
return `opencode.workspace.${head}.${sum}.dat:workspace:${key}`
|
return `opencode.workspace.${head}.${sum}.dat:workspace:${key}`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -104,4 +104,12 @@ describe("persist localStorage resilience", () => {
|
||||||
const result = persistTesting.normalize({ value: "ok" }, '{"value":"\\x"}')
|
const result = persistTesting.normalize({ value: "ok" }, '{"value":"\\x"}')
|
||||||
expect(result).toBeUndefined()
|
expect(result).toBeUndefined()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("workspace storage sanitizes Windows filename characters", () => {
|
||||||
|
const result = persistTesting.workspaceStorage("C:\\Users\\foo")
|
||||||
|
|
||||||
|
expect(result).toStartWith("opencode.workspace.")
|
||||||
|
expect(result.endsWith(".dat")).toBeTrue()
|
||||||
|
expect(/[:\\/]/.test(result)).toBeFalse()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -204,7 +204,7 @@ function normalize(defaults: unknown, raw: string, migrate?: (value: unknown) =>
|
||||||
}
|
}
|
||||||
|
|
||||||
function workspaceStorage(dir: string) {
|
function workspaceStorage(dir: string) {
|
||||||
const head = dir.slice(0, 12) || "workspace"
|
const head = (dir.slice(0, 12) || "workspace").replace(/[^a-zA-Z0-9._-]/g, "-")
|
||||||
const sum = checksum(dir) ?? "0"
|
const sum = checksum(dir) ?? "0"
|
||||||
return `opencode.workspace.${head}.${sum}.dat`
|
return `opencode.workspace.${head}.${sum}.dat`
|
||||||
}
|
}
|
||||||
|
|
@ -300,6 +300,7 @@ export const PersistTesting = {
|
||||||
localStorageDirect,
|
localStorageDirect,
|
||||||
localStorageWithPrefix,
|
localStorageWithPrefix,
|
||||||
normalize,
|
normalize,
|
||||||
|
workspaceStorage,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Persist = {
|
export const Persist = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue