From 1af528695be0a533e7d3575c2126a05f90bdc1bb Mon Sep 17 00:00:00 2001 From: Guillaume Salles Date: Thu, 21 Apr 2016 17:30:34 -0400 Subject: [PATCH] fix($location) : initialize locationPrototype.$$absUrl to empty string Initialize locationPrototype.$$absUrl to avoid exception when base href and current location have different dommains. Closes #11091 --- src/ng/location.js | 6 ++++++ test/ng/locationSpec.js | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/ng/location.js b/src/ng/location.js index 3c91549b53b4..73c6ef6616a3 100644 --- a/src/ng/location.js +++ b/src/ng/location.js @@ -325,6 +325,12 @@ function LocationHashbangInHtml5Url(appBase, appBaseNoFile, hashPrefix) { var locationPrototype = { + /** + * Ensure absolute url is initialized. + * @private + */ + $$absUrl:'', + /** * Are we in html5 mode? * @private diff --git a/test/ng/locationSpec.js b/test/ng/locationSpec.js index 8e1607c83146..f87bcf396493 100644 --- a/test/ng/locationSpec.js +++ b/test/ng/locationSpec.js @@ -2537,6 +2537,18 @@ describe('$location', function() { it('should throw on url(urlString, stateObject)', function() { expectThrowOnStateChange(locationUrl); }); + + it('should not throw when base path is another domain', function() { + initService({html5Mode:true,hashPrefix: '!',supportHistory: true}); + inject( + initBrowser({url:'http://domain.com/base/',basePath: 'http://otherdomain.com/base/'}), + function($location) { + expect(function() { + $location.absUrl(); + }).not.toThrow(); + } + ); + }); });