Skip to content

Commit ccb3127

Browse files
authored
Fix double slash normalization or useNavigate colon paths (#15410)
1 parent dc6bfce commit ccb3127

4 files changed

Lines changed: 46 additions & 34 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ We manage release notes in this file instead of the paginated Github Releases Pa
102102

103103
</details>
104104

105+
## v6.30.5
106+
107+
Date: 2026-08-18
108+
109+
### Patch Changes
110+
111+
- Fix double slash normalization for `useNavigate` colon urls
112+
113+
**Full Changelog**: [`v6.30.4...v6.30.5`](https://github.com/remix-run/react-router/compare/react-router@6.30.4...react-router@6.30.5)
114+
105115
## v6.30.4
106116

107117
Date: 2026-05-29
@@ -406,7 +416,7 @@ const router = createBrowserRouter(
406416
patch("root", [route]);
407417
}
408418
},
409-
},
419+
}
410420
);
411421
```
412422

@@ -1186,7 +1196,7 @@ let routes = createRoutesFromElements(
11861196
<Route index element={<Home />} />
11871197
<Route path="a" lazy={() => import("./a")} />
11881198
<Route path="b" lazy={() => import("./b")} />
1189-
</Route>,
1199+
</Route>
11901200
);
11911201
```
11921202

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fix double slash normalization for `useNavigate` colon urls
2+
3+
- As a reminder, `navigate()` is only intended for navigations within the React Router application and not for external navigations to other domains
4+
- This change may be a breaking bug fix if you are using `navigate` for external navigations

‎packages/react-router/__tests__/resolvePath-test.tsx‎

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,6 @@
11
import { resolvePath } from "react-router";
22

33
describe("resolvePath", () => {
4-
it("does not touch with protocol-less absolute paths", () => {
5-
expect(resolvePath("//google.com")).toMatchObject({
6-
pathname: "//google.com",
7-
});
8-
9-
expect(resolvePath("//google.com/../../path")).toMatchObject({
10-
pathname: "//google.com/../../path",
11-
});
12-
13-
expect(resolvePath("//google.com?q=query#hash")).toMatchObject({
14-
pathname: "//google.com",
15-
search: "?q=query",
16-
hash: "#hash",
17-
});
18-
});
19-
204
it('resolves absolute paths irrespective of the "from" pathname', () => {
215
expect(resolvePath("/search", "/inbox")).toMatchObject({
226
pathname: "/search",
@@ -79,6 +63,32 @@ describe("resolvePath", () => {
7963
spy.mockRestore();
8064
});
8165

66+
it("handles relative paths with an embedded colon", () => {
67+
expect(resolvePath("foo:bar", "/")).toMatchObject({
68+
pathname: "/foo:bar",
69+
});
70+
71+
expect(resolvePath("./foo:bar", "/")).toMatchObject({
72+
pathname: "/foo:bar",
73+
});
74+
75+
expect(resolvePath("../foo:bar", "/")).toMatchObject({
76+
pathname: "/foo:bar",
77+
});
78+
79+
expect(resolvePath("foo:bar", "/path")).toMatchObject({
80+
pathname: "/path/foo:bar",
81+
});
82+
83+
expect(resolvePath("./foo:bar", "/path")).toMatchObject({
84+
pathname: "/path/foo:bar",
85+
});
86+
87+
expect(resolvePath("../foo:bar", "/path")).toMatchObject({
88+
pathname: "/foo:bar",
89+
});
90+
});
91+
8292
it('ignores trailing slashes on the "from" pathname when resolving relative paths', () => {
8393
expect(resolvePath("../search", "/inbox/")).toMatchObject({
8494
pathname: "/search",

‎packages/router/utils.ts‎

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,23 +1145,11 @@ export function resolvePath(to: To, fromPathname = "/"): Path {
11451145

11461146
let pathname: string;
11471147
if (toPathname) {
1148-
if (isAbsoluteUrl(toPathname)) {
1149-
pathname = toPathname;
1148+
toPathname = removeDoubleSlashes(toPathname);
1149+
if (toPathname.startsWith("/")) {
1150+
pathname = resolvePathname(toPathname.substring(1), "/");
11501151
} else {
1151-
if (toPathname.includes("//")) {
1152-
let oldPathname = toPathname;
1153-
toPathname = removeDoubleSlashes(toPathname);
1154-
warning(
1155-
false,
1156-
`Pathnames cannot have embedded double slashes - normalizing ` +
1157-
`${oldPathname} -> ${toPathname}`
1158-
);
1159-
}
1160-
if (toPathname.startsWith("/")) {
1161-
pathname = resolvePathname(toPathname.substring(1), "/");
1162-
} else {
1163-
pathname = resolvePathname(toPathname, fromPathname);
1164-
}
1152+
pathname = resolvePathname(toPathname, fromPathname);
11651153
}
11661154
} else {
11671155
pathname = fromPathname;

0 commit comments

Comments
 (0)