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
27 changes: 27 additions & 0 deletions tests/normalize-path.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { expect, test, describe } from "bun:test"
import { normalizePath } from "../lib/utils/normalize-path"

describe("normalizePath", () => {
test("collapses multiple repeated slashes", () => {
expect(normalizePath("a///b///c.txt")).toBe("a/b/c.txt")
expect(normalizePath("a//b//c//d")).toBe("a/b/c/d")
})

test("is idempotent across multiple calls", () => {
const raw = "a///b//c////d//e.txt"
const pass1 = normalizePath(raw)
const pass2 = normalizePath(pass1)
expect(pass1).toBe(pass2)
expect(pass1).toBe("a/b/c/d/e.txt")
})

test("handles mixed and windows slashes", () => {
expect(normalizePath("a\\\\b\\\\c\\d")).toBe("a/b/c/d")
expect(normalizePath("a\\\\//b//\\c")).toBe("a/b/c")
})

test("handles empty and root", () => {
expect(normalizePath("")).toBe("")
expect(normalizePath("/")).toBe("")
})
})