Skip to content

Commit

Permalink
fix(vanilla): Fix baseHref parsing with chrome-extension:// urls
Browse files Browse the repository at this point in the history
Closes #304
  • Loading branch information
christopherthielen committed Jan 28, 2019
1 parent 148b16b commit f11be4d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/vanilla/browserLocationConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class BrowserLocationConfig implements LocationConfig {
private getBaseHref() {
const baseTag: HTMLBaseElement = document.getElementsByTagName('base')[0];
if (baseTag && baseTag.href) {
return baseTag.href.replace(/^(https?:)?\/\/[^/]*/, '');
return baseTag.href.replace(/^([^/:]*:)?\/\/[^/]*/, '');
}

return this._isHtml5 ? '/' : location.pathname || '/';
Expand Down
18 changes: 18 additions & 0 deletions test/vanilla.browserLocationConfigSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,24 @@ describe('BrowserLocationConfig implementation', () => {
expect(blc.baseHref()).toBe('/base');
});

it('strips off the http origin', () => {
applyBaseTag('http://localhost/base');
const blc = new BrowserLocationConfig();
expect(blc.baseHref()).toBe('/base');
});

it('strips off the https origin', () => {
applyBaseTag('https://localhost/base');
const blc = new BrowserLocationConfig();
expect(blc.baseHref()).toBe('/base');
});

it('supports chrome-extension:// urls', () => {
applyBaseTag('chrome-extension://cckppebifaokhmbkciccdindfbmacjcj/baseHref/');
const blc = new BrowserLocationConfig();
expect(blc.baseHref()).toBe('/baseHref/');
});

it('uses location.pathname if <base> is not present', () => {
const blc = new BrowserLocationConfig();
expect(blc.baseHref()).toBe(location.pathname);
Expand Down

0 comments on commit f11be4d

Please sign in to comment.