Skip to content

Commit 379a396

Browse files
authored
Remove / trimming on the end of href (#246)
* fix / trimming * fix tests
1 parent 775a157 commit 379a396

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { createMemo, getOwner, runWithOwner } from "solid-js";
22
import type { MatchFilter, MatchFilters, Params, PathMatch, Route, SetParams } from "./types";
33

44
const hasSchemeRegex = /^(?:[a-z0-9]+:)?\/\//i;
5-
const trimPathRegex = /^\/+|\/+$/g;
5+
const trimPathRegex = /^\/+|(\/)\/+$/g;
66

77
export function normalizePath(path: string, omitSlash: boolean = false) {
8-
const s = path.replace(trimPathRegex, "");
8+
const s = path.replace(trimPathRegex, "$1");
99
return s ? (omitSlash || /^[?#]/.test(s) ? s : "/" + s) : "";
1010
}
1111

test/utils.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ describe("joinPaths should", () => {
241241
test.each([
242242
["/foo", "", "/foo"],
243243
["/foo/", "/", "/foo"],
244-
["/foo/", "bar/", "/foo/bar"]
244+
["/foo/", "bar/", "/foo/bar/"]
245245
])(`strip trailing '/' (case '%s' and '%s' as '%s')`, (from, to, expected) => {
246246
const joined = joinPaths(from, to);
247247
expect(joined).toBe(expected);

0 commit comments

Comments
 (0)