Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/utils/normalize-path.ts
Original file line number Diff line number Diff line change
@@ -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)
}
Expand Down
25 changes: 25 additions & 0 deletions tests/utils/normalize-path.test.ts
Original file line number Diff line number Diff line change
@@ -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("")
})
Loading