Skip to content

Commit 1200b7e

Browse files
committed
fix(frame-router): fix double-slash in host URL processing when path is /
The way we process host URLs before passing to the client triggers a corner case where the native URL type silently ignores certain changes to the `pathname` field. This results in a bug where a path of `/` is represented to client apps as `//`. COMUI-4108
1 parent 40c308f commit 1200b7e

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

packages/iframe-coordinator/src/elements/frame-router.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,9 @@ export default class FrameRouterElement extends HTMLElement {
272272
if (!hostUrlObject.hash) {
273273
hostUrlObject.pathname = stripTrailingSlash(hostUrlObject.pathname);
274274
if (window.location.hash) {
275-
hostUrlObject.pathname += "/";
275+
if (hostUrlObject.pathname !== "/") {
276+
hostUrlObject.pathname += "/";
277+
}
276278
hostUrlObject.hash = "#";
277279
}
278280
}

packages/iframe-coordinator/src/specs/FrameRouter.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ const ENV_DATA = {
55
hostRootUrl: "https://example.com/root/",
66
};
77

8+
const ENV_DATA_SINGLE_SLASH = {
9+
...ENV_DATA,
10+
hostRootUrl: "https://example.com/",
11+
};
12+
813
const ENV_DATA_WITH_HASH = {
914
...ENV_DATA,
1015
hostRootUrl: "https://example.com/root/#/",
@@ -62,6 +67,33 @@ describe("The frame router element", () => {
6267
});
6368
});
6469

70+
it("Correctly process a host URL using the root path with no hash", () => {
71+
const router = new FrameRouterElement();
72+
router.clientConfig = {
73+
clients: {},
74+
envData: ENV_DATA_SINGLE_SLASH,
75+
};
76+
//@ts-ignore
77+
expect(router._envData).toEqual({
78+
...ENV_DATA,
79+
hostRootUrl: "https://example.com/",
80+
});
81+
});
82+
83+
it("Correctly process a host URL using the root path with a hash", () => {
84+
window.location.hash = "foo";
85+
const router = new FrameRouterElement();
86+
router.clientConfig = {
87+
clients: {},
88+
envData: ENV_DATA_SINGLE_SLASH,
89+
};
90+
//@ts-ignore
91+
expect(router._envData).toEqual({
92+
...ENV_DATA,
93+
hostRootUrl: "https://example.com/#",
94+
});
95+
});
96+
6597
it("Does not modify the provided host URL if it and the current location have a fragment", () => {
6698
window.location.hash = "foo";
6799
const router = new FrameRouterElement();

0 commit comments

Comments
 (0)