Skip to content
Closed
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
4 changes: 3 additions & 1 deletion packages/common/src/location/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,9 @@ export function createLocation() {
}

function _stripBasePath(basePath: string, url: string): string {
return basePath && url.startsWith(basePath) ? url.substring(basePath.length) : url;
return basePath && new RegExp(`^${basePath}([/;?#]|$)`).test(url) ?
url.substring(basePath.length) :
url;
}

function _stripIndexHtml(url: string): string {
Expand Down
21 changes: 21 additions & 0 deletions packages/common/test/location/location_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,25 @@ describe('Location Class', () => {
expect(location.normalize(url)).toBe(route);
});
});

describe('location.normalize(url) should return properly normalized url', () => {
it('in case url starts with the substring equals APP_BASE_HREF', () => {
const baseHref = '/en';
const path = '/enigma';
const queryParams = '?param1=123';
const matrixParams = ';param1=123';
const fragment = '#anchor1';

TestBed.configureTestingModule({providers: [{provide: APP_BASE_HREF, useValue: baseHref}]});

const location = TestBed.inject(Location);

expect(location.normalize(path)).toBe(path);
expect(location.normalize(baseHref)).toBe('');
expect(location.normalize(baseHref + path)).toBe(path);
expect(location.normalize(baseHref + queryParams)).toBe(queryParams);
expect(location.normalize(baseHref + matrixParams)).toBe(matrixParams);
expect(location.normalize(baseHref + fragment)).toBe(fragment);
});
});
});