Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.

Fixed bug where navigating to a URL that is a partial match to the… #372

Merged
merged 2 commits into from
Mar 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 21 additions & 0 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ describe('AppComponent', () => {
};
scrollCalled = false;
viewport = new SkyAppViewportService();
navigateByUrlParams = undefined;
});

it('should create component', async(() => {
Expand Down Expand Up @@ -576,6 +577,26 @@ describe('AppComponent', () => {
});
}));

it('should handle global links that start with the same base URL as the SPA', async(() => {
let spyOmnibar = spyOn(BBOmnibar, 'load');

skyAppConfig.skyux.omnibar = {
experimental: true
};

skyAppConfig.skyux.host.url = 'base.com/';
skyAppConfig.runtime.app.base = 'custom-base/';

setup(skyAppConfig, false).then(() => {
fixture.detectChanges();
const cb = spyOmnibar.calls.first().args[0].nav.beforeNavCallback;

let globalLink = cb({ url: 'base.com/custom-base-2' });
expect(globalLink).toEqual(true);
expect(navigateByUrlParams).not.toBeDefined();
});
}));

it('should use the original url casing if calling navigateByUrl', async(() => {
let spyOmnibar = spyOn(BBOmnibar, 'load');

Expand Down
8 changes: 7 additions & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,13 @@ export class AppComponent implements OnInit {
nav.beforeNavCallback = (item: BBOmnibarNavigationItem) => {
const url = item.url.toLowerCase();

if (url.indexOf(baseUrl) === 0) {
if (
url === baseUrl ||
// Make sure the base URL is not simply a partial match of the base URL plus additional
// characters after the base URL that are not "terminating" characters
url.indexOf(baseUrl + '/') === 0 ||
url.indexOf(baseUrl + '?') === 0
) {
const routePath = item.url.substring(baseUrl.length, url.length);

// Since the omnibar is loaded outside Angular, navigating needs to be explicitly
Expand Down