From e306cbe3a77988e2c083cb0ad61de7e54b00a10c Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Thu, 2 Jan 2014 19:12:31 -0500 Subject: [PATCH] fix($browser): remove base href domain when url begins with '//' This change prevents an incorrect appBase url from being calculated when the href's domain begins with '//'. Closes #5606 --- src/ng/browser.js | 2 +- test/ng/browserSpecs.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ng/browser.js b/src/ng/browser.js index 68e8ba9383ee..3bb51b57606d 100644 --- a/src/ng/browser.js +++ b/src/ng/browser.js @@ -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?\:)?\/\/[^\/]*/, '') : ''; }; ////////////////////////////////////////////////////////////// diff --git a/test/ng/browserSpecs.js b/test/ng/browserSpecs.js index 6c6ac30e2195..4157ecbdb7fd 100755 --- a/test/ng/browserSpecs.js +++ b/test/ng/browserSpecs.js @@ -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 beginning with \'//\'', function() { + fakeDocument.basePath = '//google.com/base/path/'; + expect(browser.baseHref()).toEqual('/base/path/'); + }); }); });