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

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

function _stripIndexHtml(url: string): string {
Expand Down
13 changes: 13 additions & 0 deletions packages/common/test/location/location_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,5 +286,18 @@ describe('Location Class', () => {
expect(location.normalize(baseHref + matrixParams)).toBe(matrixParams);
expect(location.normalize(baseHref + fragment)).toBe(fragment);
});

it('in case APP_BASE_HREF contains characters that have special meaning in a regex', () => {
const baseHref = 'c:/users/name(test)/en';
const path = '/test-path';

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);
});
});
});