Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refactoring hash logic to fix possible issue with query param on host route (i.e. timemachine override) #271

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
4a38968
fix: removing slash to fix possible issue with query param on host ro…
jordanstith15 Jul 9, 2024
8edc7aa
Merge branch 'main' into feature/COMUI-1386
jordanstith15 Nov 4, 2024
fe81aef
chore: updating lockfile after syncing with main
jordanstith15 Nov 4, 2024
1057281
chore: refactoring processHostUrl function to just use a URL object
jordanstith15 Nov 6, 2024
13c6080
feat(ifc-cli): add support for proxy configuration via a json file
MattCheely Nov 7, 2024
cd15328
chore(release): 6.1.0
Dec 2, 2024
cf36ab1
chore: updating package-lock after syncing with main
jordanstith15 Dec 9, 2024
fe2b77e
Merge branch 'main' of github.com:purecloudlabs/iframe-coordinator in…
jordanstith15 Dec 19, 2024
8945ffd
chore(frame-router): simplifying if clause in processHostUrl
jordanstith15 Jan 7, 2025
cf19d6b
Merge branch 'main' of github.com:purecloudlabs/iframe-coordinator in…
jordanstith15 Jan 7, 2025
32b707f
chore(ifc-example): changing the hostRootUrl for the example ifc conf…
jordanstith15 Jan 9, 2025
3c39a0e
Merge branch 'main' of github.com:purecloudlabs/iframe-coordinator in…
jordanstith15 Jan 14, 2025
a250811
chore(ifc-example): updating lockfile after syncing with main
jordanstith15 Jan 14, 2025
274ff77
Merge branch 'main' of github.com:purecloudlabs/iframe-coordinator in…
jordanstith15 Jan 30, 2025
79ec9ea
chore(lockfile): updating lockfile after syncing with main
jordanstith15 Jan 30, 2025
bae081a
chore(frame-router): refactoring to pass tests, adding tests for quer…
jordanstith15 Feb 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apps/ifc-example-client/ifc-cli.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ module.exports = function (frameRouter) {
},
envData: {
locale: "en-US",
hostRootUrl: window.location.origin + "/#/",
hostRootUrl:
window.location.origin +
window.location.pathname +
window.location.search,
registeredKeys: [
{ key: "a", ctrlKey: true },
{ key: "b", altKey: true },
Expand Down
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion packages/iframe-coordinator-cli/src/example-ifc.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ module.exports = function (frameRouter) {
},
envData: {
locale: "en-US",
hostRootUrl: window.location.origin,
hostRootUrl:
window.location.origin +
window.location.pathname +
window.location.search,
registeredKeys: [
{ key: "a", ctrlKey: true },
{ key: "b", altKey: true },
Expand Down
11 changes: 7 additions & 4 deletions packages/iframe-coordinator/src/elements/frame-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,13 @@ export default class FrameRouterElement extends HTMLElement {

private _processHostUrl(hostUrl: string) {
const hostUrlObject = new URL(hostUrl);
if (hostUrlObject.hash) {
return hostUrlObject.href;
if (!hostUrlObject.hash) {
hostUrlObject.pathname = stripTrailingSlash(hostUrlObject.pathname);
if (window.location.hash) {
hostUrlObject.pathname += "/";
hostUrlObject.hash = "#";
}
}
const trimmedUrl = stripTrailingSlash(hostUrl);
return window.location.hash ? `${trimmedUrl}/#` : trimmedUrl;
return hostUrlObject.href;
}
}
51 changes: 49 additions & 2 deletions packages/iframe-coordinator/src/specs/FrameRouter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ const ENV_DATA_WITH_HASH = {
hostRootUrl: "https://example.com/root/#/",
};

const ENV_DATA_WITH_QUERY = {
...ENV_DATA,
hostRootUrl: "https://example.com/root/?foo=bar",
};

const ENV_DATA_WITH_QUERY_AND_HASH = {
...ENV_DATA,
hostRootUrl: "https://example.com/root/?foo=bar#/",
};

describe("The frame router element", () => {
beforeAll(() => {
window.customElements.define("frame-router", FrameRouterElement);
Expand All @@ -25,7 +35,7 @@ describe("The frame router element", () => {
* behavior.
*/
describe("Host URL management", () => {
it("Removes a trailing slash on the host URL if present", () => {
it("Removes a trailing slash on the host URL if present with no hash", () => {
const router = new FrameRouterElement();
router.clientConfig = {
clients: {},
Expand Down Expand Up @@ -65,6 +75,43 @@ describe("The frame router element", () => {
});
});

// TODO: Test expected query behavior here
it("Removes trailing slash from pathname when the provided host URL with query params; urlObject and location have no hash", () => {
const router = new FrameRouterElement();
router.clientConfig = {
clients: {},
envData: ENV_DATA_WITH_QUERY,
};
//@ts-ignore
expect(router._envData).toEqual({
...ENV_DATA_WITH_QUERY,
hostRootUrl: "https://example.com/root?foo=bar",
});
});

it("Does not add slash between hash and query params if location has hash; urlObject has no hash", () => {
window.location.hash = "foo";
const router = new FrameRouterElement();
router.clientConfig = {
clients: {},
envData: ENV_DATA_WITH_QUERY,
};
//@ts-ignore
expect(router._envData).toEqual({
...ENV_DATA_WITH_QUERY,
hostRootUrl: "https://example.com/root/?foo=bar#",
});
});

it("Does not modify provided host URL with query params if urlObject has hash; location hash N/A", () => {
const router = new FrameRouterElement();
router.clientConfig = {
clients: {},
envData: ENV_DATA_WITH_QUERY_AND_HASH,
};
//@ts-ignore
expect(router._envData).toEqual({
...ENV_DATA_WITH_QUERY_AND_HASH,
});
});
});
});