From ba6b2d837e4571c88077b4a2a4b9ca6b91c662d7 Mon Sep 17 00:00:00 2001 From: 2503piglu <144887487+2503piglu@users.noreply.github.com> Date: Sun, 11 Oct 2026 13:40:30 +0530 Subject: [PATCH 1/2] fix(utils): make normalizePath idempotent by globally collapsing repeated slashes --- lib/utils/normalize-path.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) } From 810fa42b1d8c510ac0c3bbe40f2e15536d69aba5 Mon Sep 17 00:00:00 2001 From: 2503piglu <144887487+2503piglu@users.noreply.github.com> Date: Sun, 11 Oct 2026 13:43:51 +0530 Subject: [PATCH 2/2] test(utils): add normalizePath tests Add tests for normalizePath function covering various cases. --- tests/utils/normalize-path.test.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/utils/normalize-path.test.ts diff --git a/tests/utils/normalize-path.test.ts b/tests/utils/normalize-path.test.ts new file mode 100644 index 0000000..48ae813 --- /dev/null +++ b/tests/utils/normalize-path.test.ts @@ -0,0 +1,25 @@ +import { expect, it } from "bun:test" +import { normalizePath } from "lib/utils/normalize-path" + +it("collapses repeated slashes across the entire path", () => { + expect(normalizePath("a///b///c.txt")).toBe("a/b/c.txt") + expect(normalizePath("a//b//c//d")).toBe("a/b/c/d") +}) + +it("is idempotent", () => { + const once = normalizePath("a///b//c///d.txt") + expect(normalizePath(once)).toBe(once) + expect(once).toBe("a/b/c/d.txt") +}) + +it("converts backslashes and collapses repeated slashes", () => { + expect(normalizePath("a\\\\b\\\\c")).toBe("a/b/c") + expect(normalizePath("a\\\\\\b//c")).toBe("a/b/c") +}) + +it("handles leading, trailing and root slashes", () => { + expect(normalizePath("/a/b/c/")).toBe("a/b/c") + expect(normalizePath("///a//b///")).toBe("a/b") + expect(normalizePath("/")).toBe("") + expect(normalizePath("")).toBe("") +})