From a7c25ee95e1f80e58776a0c55a6abec12ffe5582 Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Wed, 7 Jun 2023 11:16:04 -0400 Subject: [PATCH] [MM-53056] Force a pathname when checking for deep links (#2748) --- src/common/servers/serverManager.test.js | 1 + src/common/servers/serverManager.ts | 6 +++--- src/main/views/viewManager.test.js | 1 + src/main/views/viewManager.ts | 4 ++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/common/servers/serverManager.test.js b/src/common/servers/serverManager.test.js index 5d5d6e79..f1a0945a 100644 --- a/src/common/servers/serverManager.test.js +++ b/src/common/servers/serverManager.test.js @@ -13,6 +13,7 @@ jest.mock('common/config', () => ({ jest.mock('common/utils/url', () => ({ parseURL: jest.fn(), isInternalURL: jest.fn(), + getFormattedPathName: (pathname) => (pathname.length ? pathname : '/'), })); jest.mock('common/utils/util', () => ({ isVersionGreaterThanOrEqualTo: jest.fn(), diff --git a/src/common/servers/serverManager.ts b/src/common/servers/serverManager.ts index b36445a4..1820d034 100644 --- a/src/common/servers/serverManager.ts +++ b/src/common/servers/serverManager.ts @@ -17,7 +17,7 @@ import {TAB_FOCALBOARD, TAB_MESSAGING, TAB_PLAYBOOKS, MattermostView, getDefault import MessagingView from 'common/views/MessagingView'; import FocalboardView from 'common/views/FocalboardView'; import PlaybooksView from 'common/views/PlaybooksView'; -import {isInternalURL, parseURL} from 'common/utils/url'; +import {getFormattedPathName, isInternalURL, parseURL} from 'common/utils/url'; import Utils from 'common/utils/util'; const log = new Logger('ServerManager'); @@ -138,7 +138,7 @@ export class ServerManager extends EventEmitter { return undefined; } const server = this.getAllServers().find((server) => { - return isInternalURL(parsedURL, server.url, ignoreScheme) && parsedURL.pathname.match(new RegExp(`^${server.url.pathname}(.+)?(/(.+))?$`)); + return isInternalURL(parsedURL, server.url, ignoreScheme) && getFormattedPathName(parsedURL.pathname).match(new RegExp(`^${server.url.pathname}(.+)?(/(.+))?$`)); }); if (!server) { return undefined; @@ -149,7 +149,7 @@ export class ServerManager extends EventEmitter { views. filter((view) => view && view.type !== TAB_MESSAGING). forEach((view) => { - if (parsedURL.pathname.match(new RegExp(`^${view.url.pathname}(/(.+))?`))) { + if (getFormattedPathName(parsedURL.pathname).match(new RegExp(`^${view.url.pathname}(/(.+))?`))) { selectedView = view; } }); diff --git a/src/main/views/viewManager.test.js b/src/main/views/viewManager.test.js index e164f73e..cbdc9657 100644 --- a/src/main/views/viewManager.test.js +++ b/src/main/views/viewManager.test.js @@ -50,6 +50,7 @@ jest.mock('common/utils/url', () => ({ return null; } }, + getFormattedPathName: (pathname) => (pathname.length ? pathname : '/'), equalUrlsIgnoringSubpath: jest.fn(), })); diff --git a/src/main/views/viewManager.ts b/src/main/views/viewManager.ts index 05f9067d..4b853ce2 100644 --- a/src/main/views/viewManager.ts +++ b/src/main/views/viewManager.ts @@ -34,7 +34,7 @@ import Utils from 'common/utils/util'; import {MattermostServer} from 'common/servers/MattermostServer'; import ServerManager from 'common/servers/serverManager'; import {MattermostView, TAB_MESSAGING} from 'common/views/View'; -import {parseURL} from 'common/utils/url'; +import {getFormattedPathName, parseURL} from 'common/utils/url'; import {localizeMessage} from 'main/i18nManager'; import MainWindow from 'main/windows/mainWindow'; @@ -177,7 +177,7 @@ export class ViewManager { const parsedURL = parseURL(url)!; const view = ServerManager.lookupViewByURL(parsedURL, true); if (view) { - const urlWithSchema = `${view.url.origin}${parsedURL.pathname}${parsedURL.search}`; + const urlWithSchema = `${view.url.origin}${getFormattedPathName(parsedURL.pathname)}${parsedURL.search}`; if (this.closedViews.has(view.id)) { this.openClosedView(view.id, urlWithSchema); } else {