Skip to content

Commit

Permalink
fix($browser): remove base href domain when url begins with '//'
Browse files Browse the repository at this point in the history
This change prevents an incorrect appBase url from being calculated when the
<base> href's domain begins with '//'.

Closes angular#5606
  • Loading branch information
caitp authored and jamesdaily committed Jan 27, 2014
1 parent fbc60d2 commit e306cbe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ng/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ function Browser(window, document, $log, $sniffer) {
*/
self.baseHref = function() {
var href = baseElement.attr('href');
return href ? href.replace(/^https?\:\/\/[^\/]*/, '') : '';
return href ? href.replace(/^(https?\:)?\/\/[^\/]*/, '') : '';
};

//////////////////////////////////////////////////////////////
Expand Down
5 changes: 5 additions & 0 deletions test/ng/browserSpecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,5 +609,10 @@ describe('browser', function() {
fakeDocument.basePath = 'http://host.com/base/path/index.html';
expect(browser.baseHref()).toEqual('/base/path/index.html');
});

it('should remove domain from <base href> beginning with \'//\'', function() {
fakeDocument.basePath = '//google.com/base/path/';
expect(browser.baseHref()).toEqual('/base/path/');
});
});
});

0 comments on commit e306cbe

Please sign in to comment.