From b282218d7134490f04fb68d80df371b3495d2de1 Mon Sep 17 00:00:00 2001 From: vagdotdev Date: Tue, 30 Jun 2026 02:02:05 +0530 Subject: [PATCH] fix: normalize all repeated path slashes --- lib/utils/normalize-path.ts | 2 +- tests/fixtures/get-test-server.ts | 5 ++--- tests/routes/files.test.ts | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/utils/normalize-path.ts b/lib/utils/normalize-path.ts index debc468..7b8c4af 100644 --- a/lib/utils/normalize-path.ts +++ b/lib/utils/normalize-path.ts @@ -1,6 +1,6 @@ export function normalizePath(path: string): string { if (!path || path === "/") return "" - let normalized = path.replace(/\\+/g, "/").replace(/\/\/+/, "/") + let normalized = path.replace(/\\+/g, "/").replace(/\/\/+/g, "/") if (normalized.startsWith("/")) { normalized = normalized.slice(1) } diff --git a/tests/fixtures/get-test-server.ts b/tests/fixtures/get-test-server.ts index 7063c41..1d1243e 100644 --- a/tests/fixtures/get-test-server.ts +++ b/tests/fixtures/get-test-server.ts @@ -10,16 +10,15 @@ interface TestFixture { } export const getTestServer = async (): Promise => { - const port = 3001 + Math.floor(Math.random() * 999) const testInstanceId = Math.random().toString(36).substring(2, 15) const testDbName = `testdb${testInstanceId}` const server = await startServer({ - port, + port: 0, testDbName, }) - const url = `http://127.0.0.1:${port}` + const url = `http://127.0.0.1:${server.port}` const axios = defaultAxios.create({ baseURL: url, }) diff --git a/tests/routes/files.test.ts b/tests/routes/files.test.ts index 196c354..e3ddf9e 100644 --- a/tests/routes/files.test.ts +++ b/tests/routes/files.test.ts @@ -112,6 +112,22 @@ test("file download operations2", async () => { }) }) +test("download query paths normalize every repeated slash run", async () => { + const { axios } = await getTestServer() + + await axios.post("/files/upsert", { + file_path: "/normalized/path/file.txt", + text_content: "Normalized repeated slashes", + }) + + const downloadRes = await axios.get("/files/download", { + params: { file_path: "/normalized//path///file.txt" }, + }) + + expect(downloadRes.status).toBe(200) + expect(downloadRes.data).toBe("Normalized repeated slashes") +}) + test("file delete operations", async () => { const { axios } = await getTestServer()