[MM-54872] Ensure matched subpaths are exact and not substrings of each other (#2958)
This commit is contained in:
parent
1a7516aac9
commit
68034b166f
|
@ -13,7 +13,7 @@ jest.mock('common/config', () => ({
|
|||
jest.mock('common/utils/url', () => ({
|
||||
parseURL: jest.fn(),
|
||||
isInternalURL: jest.fn(),
|
||||
getFormattedPathName: (pathname) => (pathname.length ? pathname : '/'),
|
||||
getFormattedPathName: (pathname) => (pathname.endsWith('/') ? pathname : `${pathname}/`),
|
||||
}));
|
||||
jest.mock('common/utils/util', () => ({
|
||||
isVersionGreaterThanOrEqualTo: jest.fn(),
|
||||
|
@ -128,6 +128,11 @@ describe('common/servers/serverManager', () => {
|
|||
expect(serverManager.lookupViewByURL(inputURL)).toStrictEqual({id: 'view-2', url: new URL('http://server-2.com/subpath')});
|
||||
});
|
||||
|
||||
it('should not match a server where the subpaths are substrings of each other ', () => {
|
||||
const inputURL = new URL('http://server-2.com/subpath2');
|
||||
expect(serverManager.lookupViewByURL(inputURL)).toBe(undefined);
|
||||
});
|
||||
|
||||
it('should match the correct server with a subpath - base view', () => {
|
||||
const inputURL = new URL('http://server-2.com/subpath/server');
|
||||
expect(serverManager.lookupViewByURL(inputURL)).toStrictEqual({id: 'view-2', url: new URL('http://server-2.com/subpath')});
|
||||
|
|
|
@ -123,7 +123,7 @@ export class ServerManager extends EventEmitter {
|
|||
}
|
||||
const server = this.getAllServers().find((server) => {
|
||||
return isInternalURL(parsedURL, server.url, ignoreScheme) &&
|
||||
getFormattedPathName(parsedURL.pathname).startsWith(server.url.pathname);
|
||||
getFormattedPathName(parsedURL.pathname).startsWith(getFormattedPathName(server.url.pathname));
|
||||
});
|
||||
if (!server) {
|
||||
return undefined;
|
||||
|
@ -134,7 +134,7 @@ export class ServerManager extends EventEmitter {
|
|||
views.
|
||||
filter((view) => view && view.type !== TAB_MESSAGING).
|
||||
forEach((view) => {
|
||||
if (getFormattedPathName(parsedURL.pathname).startsWith(view.url.pathname)) {
|
||||
if (getFormattedPathName(parsedURL.pathname).startsWith(getFormattedPathName(view.url.pathname))) {
|
||||
selectedView = view;
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue