Skip to content

Commit f11be4d

Browse files
fix(vanilla): Fix baseHref parsing with chrome-extension:// urls
Closes #304
1 parent 148b16b commit f11be4d

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/vanilla/browserLocationConfig.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class BrowserLocationConfig implements LocationConfig {
4444
private getBaseHref() {
4545
const baseTag: HTMLBaseElement = document.getElementsByTagName('base')[0];
4646
if (baseTag && baseTag.href) {
47-
return baseTag.href.replace(/^(https?:)?\/\/[^/]*/, '');
47+
return baseTag.href.replace(/^([^/:]*:)?\/\/[^/]*/, '');
4848
}
4949

5050
return this._isHtml5 ? '/' : location.pathname || '/';

test/vanilla.browserLocationConfigSpec.ts

+18
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,24 @@ describe('BrowserLocationConfig implementation', () => {
128128
expect(blc.baseHref()).toBe('/base');
129129
});
130130

131+
it('strips off the http origin', () => {
132+
applyBaseTag('http://localhost/base');
133+
const blc = new BrowserLocationConfig();
134+
expect(blc.baseHref()).toBe('/base');
135+
});
136+
137+
it('strips off the https origin', () => {
138+
applyBaseTag('https://localhost/base');
139+
const blc = new BrowserLocationConfig();
140+
expect(blc.baseHref()).toBe('/base');
141+
});
142+
143+
it('supports chrome-extension:// urls', () => {
144+
applyBaseTag('chrome-extension://cckppebifaokhmbkciccdindfbmacjcj/baseHref/');
145+
const blc = new BrowserLocationConfig();
146+
expect(blc.baseHref()).toBe('/baseHref/');
147+
});
148+
131149
it('uses location.pathname if <base> is not present', () => {
132150
const blc = new BrowserLocationConfig();
133151
expect(blc.baseHref()).toBe(location.pathname);

0 commit comments

Comments
 (0)