summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLuke Parker <[email protected]>2026-03-07 14:34:29 +1000
committerGitHub <[email protected]>2026-03-07 04:34:29 +0000
commit4c7fe6049346def59e06c676c6bdec1a72c72470 (patch)
tree0e63d69760416b1ea70702e9ef59a2c04d6f9363
parentc108f304c6e13bd4028ade5a138c38b63d3c49a3 (diff)
downloadopencode-4c7fe6049346def59e06c676c6bdec1a72c72470.tar.gz
opencode-4c7fe6049346def59e06c676c6bdec1a72c72470.zip
fix(opencode): sanitize preview database filenames (#16430)
-rw-r--r--packages/opencode/src/storage/db.ts12
-rw-r--r--packages/opencode/test/storage/db.test.ts12
2 files changed, 19 insertions, 5 deletions
diff --git a/packages/opencode/src/storage/db.ts b/packages/opencode/src/storage/db.ts
index d7538dc70..d6f8b2ab5 100644
--- a/packages/opencode/src/storage/db.ts
+++ b/packages/opencode/src/storage/db.ts
@@ -27,12 +27,14 @@ export const NotFoundError = NamedError.create(
const log = Log.create({ service: "db" })
export namespace Database {
+ export function file(channel: string) {
+ if (channel === "latest" || Flag.OPENCODE_DISABLE_CHANNEL_DB) return "opencode.db"
+ const safe = channel.replace(/[^a-zA-Z0-9._-]/g, "-")
+ return `opencode-${safe}.db`
+ }
+
export const Path = (() => {
- const name =
- Installation.CHANNEL !== "latest" && !Flag.OPENCODE_DISABLE_CHANNEL_DB
- ? `opencode-${Installation.CHANNEL}.db`
- : "opencode.db"
- return path.join(Global.Path.data, name)
+ return path.join(Global.Path.data, file(Installation.CHANNEL))
})()
type Schema = typeof schema
diff --git a/packages/opencode/test/storage/db.test.ts b/packages/opencode/test/storage/db.test.ts
new file mode 100644
index 000000000..47908e281
--- /dev/null
+++ b/packages/opencode/test/storage/db.test.ts
@@ -0,0 +1,12 @@
+import { describe, expect, test } from "bun:test"
+import { Database } from "../../src/storage/db"
+
+describe("Database.file", () => {
+ test("uses the shared database for latest", () => {
+ expect(Database.file("latest")).toBe("opencode.db")
+ })
+
+ test("sanitizes preview channels for filenames", () => {
+ expect(Database.file("fix/windows-modified-files-tracking")).toBe("opencode-fix-windows-modified-files-tracking.db")
+ })
+})