Skip to content

Commit 88fc61d

Browse files
caitpjamesdaily
authored andcommitted
fix($browser): remove base href domain when url begins with '//'
This change prevents an incorrect appBase url from being calculated when the <base> href's domain begins with '//'. Closes angular#5606
1 parent c9bdaee commit 88fc61d

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/ng/browser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ function Browser(window, document, $log, $sniffer) {
253253
*/
254254
self.baseHref = function() {
255255
var href = baseElement.attr('href');
256-
return href ? href.replace(/^https?\:\/\/[^\/]*/, '') : '';
256+
return href ? href.replace(/^(https?\:)?\/\/[^\/]*/, '') : '';
257257
};
258258

259259
//////////////////////////////////////////////////////////////

test/ng/browserSpecs.js

+5
Original file line numberDiff line numberDiff line change
@@ -609,5 +609,10 @@ describe('browser', function() {
609609
fakeDocument.basePath = 'http://host.com/base/path/index.html';
610610
expect(browser.baseHref()).toEqual('/base/path/index.html');
611611
});
612+
613+
it('should remove domain from <base href> beginning with \'//\'', function() {
614+
fakeDocument.basePath = '//google.com/base/path/';
615+
expect(browser.baseHref()).toEqual('/base/path/');
616+
});
612617
});
613618
});

0 commit comments

Comments
 (0)