Skip to content

Commit b94fe40

Browse files
Merge pull request #271 from purecloudlabs/feature/COMUI-1386
fix: refactoring hash logic to fix possible issue with query param on host route (i.e. timemachine override)
2 parents 79e7481 + bae081a commit b94fe40

File tree

5 files changed

+72
-8
lines changed

5 files changed

+72
-8
lines changed

apps/ifc-example-client/ifc-cli.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ module.exports = function (frameRouter) {
2828
},
2929
envData: {
3030
locale: "en-US",
31-
hostRootUrl: window.location.origin + "/#/",
31+
hostRootUrl:
32+
window.location.origin +
33+
window.location.pathname +
34+
window.location.search,
3235
registeredKeys: [
3336
{ key: "a", ctrlKey: true },
3437
{ key: "b", altKey: true },

package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/iframe-coordinator-cli/src/example-ifc.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ module.exports = function (frameRouter) {
1515
},
1616
envData: {
1717
locale: "en-US",
18-
hostRootUrl: window.location.origin,
18+
hostRootUrl:
19+
window.location.origin +
20+
window.location.pathname +
21+
window.location.search,
1922
registeredKeys: [
2023
{ key: "a", ctrlKey: true },
2124
{ key: "b", altKey: true },

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,13 @@ export default class FrameRouterElement extends HTMLElement {
269269

270270
private _processHostUrl(hostUrl: string) {
271271
const hostUrlObject = new URL(hostUrl);
272-
if (hostUrlObject.hash) {
273-
return hostUrlObject.href;
272+
if (!hostUrlObject.hash) {
273+
hostUrlObject.pathname = stripTrailingSlash(hostUrlObject.pathname);
274+
if (window.location.hash) {
275+
hostUrlObject.pathname += "/";
276+
hostUrlObject.hash = "#";
277+
}
274278
}
275-
const trimmedUrl = stripTrailingSlash(hostUrl);
276-
return window.location.hash ? `${trimmedUrl}/#` : trimmedUrl;
279+
return hostUrlObject.href;
277280
}
278281
}

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

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ const ENV_DATA_WITH_HASH = {
1010
hostRootUrl: "https://example.com/root/#/",
1111
};
1212

13+
const ENV_DATA_WITH_QUERY = {
14+
...ENV_DATA,
15+
hostRootUrl: "https://example.com/root/?foo=bar",
16+
};
17+
18+
const ENV_DATA_WITH_QUERY_AND_HASH = {
19+
...ENV_DATA,
20+
hostRootUrl: "https://example.com/root/?foo=bar#/",
21+
};
22+
1323
describe("The frame router element", () => {
1424
beforeAll(() => {
1525
window.customElements.define("frame-router", FrameRouterElement);
@@ -25,7 +35,7 @@ describe("The frame router element", () => {
2535
* behavior.
2636
*/
2737
describe("Host URL management", () => {
28-
it("Removes a trailing slash on the host URL if present", () => {
38+
it("Removes a trailing slash on the host URL if present with no hash", () => {
2939
const router = new FrameRouterElement();
3040
router.clientConfig = {
3141
clients: {},
@@ -65,6 +75,43 @@ describe("The frame router element", () => {
6575
});
6676
});
6777

68-
// TODO: Test expected query behavior here
78+
it("Removes trailing slash from pathname when the provided host URL with query params; urlObject and location have no hash", () => {
79+
const router = new FrameRouterElement();
80+
router.clientConfig = {
81+
clients: {},
82+
envData: ENV_DATA_WITH_QUERY,
83+
};
84+
//@ts-ignore
85+
expect(router._envData).toEqual({
86+
...ENV_DATA_WITH_QUERY,
87+
hostRootUrl: "https://example.com/root?foo=bar",
88+
});
89+
});
90+
91+
it("Does not add slash between hash and query params if location has hash; urlObject has no hash", () => {
92+
window.location.hash = "foo";
93+
const router = new FrameRouterElement();
94+
router.clientConfig = {
95+
clients: {},
96+
envData: ENV_DATA_WITH_QUERY,
97+
};
98+
//@ts-ignore
99+
expect(router._envData).toEqual({
100+
...ENV_DATA_WITH_QUERY,
101+
hostRootUrl: "https://example.com/root/?foo=bar#",
102+
});
103+
});
104+
105+
it("Does not modify provided host URL with query params if urlObject has hash; location hash N/A", () => {
106+
const router = new FrameRouterElement();
107+
router.clientConfig = {
108+
clients: {},
109+
envData: ENV_DATA_WITH_QUERY_AND_HASH,
110+
};
111+
//@ts-ignore
112+
expect(router._envData).toEqual({
113+
...ENV_DATA_WITH_QUERY_AND_HASH,
114+
});
115+
});
69116
});
70117
});

0 commit comments

Comments
 (0)