fix(path): handle lone slash

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
Aaron Pham 2025-01-07 15:47:23 -05:00
parent 2e6a675edd
commit d43d7ade78
No known key found for this signature in database
GPG Key ID: 18974753009D2BFA
2 changed files with 5 additions and 1 deletions

View File

@ -171,6 +171,10 @@ describe("transforms", () => {
assert.strictEqual(path.joinSegments("/a", "b/"), "/a/b/")
assert.strictEqual(path.joinSegments("/a/", "b/"), "/a/b/")
// lone slash
assert.strictEqual(path.joinSegments("/a/", "b", "/"), "/a/b/")
assert.strictEqual(path.joinSegments("a/", "b" + "/"), "a/b/")
// works with protocol specifiers
assert.strictEqual(path.joinSegments("https://example.com", "a"), "https://example.com/a")
assert.strictEqual(path.joinSegments("https://example.com/", "a"), "https://example.com/a")

View File

@ -188,7 +188,7 @@ export function joinSegments(...args: string[]): string {
}
let joined = args
.filter((segment) => segment !== "")
.filter((segment) => segment !== "" && segment !== "/")
.map((segment) => stripSlashes(segment))
.join("/")