diff --git a/src/ng/browser.js b/src/ng/browser.js index 3f5f125ed4c3..afe06a4207dc 100644 --- a/src/ng/browser.js +++ b/src/ng/browser.js @@ -133,6 +133,9 @@ function Browser(window, document, $log, $sniffer) { if (url) { var sameState = lastHistoryState === state; + // Normalize the inputted URL + url = urlResolve(url).href; + // Don't change anything if previous and current URLs and states match. This also prevents // IE<10 from getting into redirect loop when in LocationHashbangInHtml5Url mode. // See https://github.com/angular/angular.js/commit/ffb2701 diff --git a/test/ng/browserSpecs.js b/test/ng/browserSpecs.js index 074e4404830a..9f312ed6aeb9 100644 --- a/test/ng/browserSpecs.js +++ b/test/ng/browserSpecs.js @@ -296,7 +296,7 @@ describe('browser', function() { browser.url('http://new.org'); expect(pushState).toHaveBeenCalledOnce(); - expect(pushState.calls.argsFor(0)[2]).toEqual('http://new.org'); + expect(pushState.calls.argsFor(0)[2]).toEqual('http://new.org/'); expect(replaceState).not.toHaveBeenCalled(); expect(locationReplace).not.toHaveBeenCalled(); @@ -308,7 +308,7 @@ describe('browser', function() { browser.url('http://new.org', true); expect(replaceState).toHaveBeenCalledOnce(); - expect(replaceState.calls.argsFor(0)[2]).toEqual('http://new.org'); + expect(replaceState.calls.argsFor(0)[2]).toEqual('http://new.org/'); expect(pushState).not.toHaveBeenCalled(); expect(locationReplace).not.toHaveBeenCalled(); @@ -319,7 +319,7 @@ describe('browser', function() { sniffer.history = false; browser.url('http://new.org'); - expect(fakeWindow.location.href).toEqual('http://new.org'); + expect(fakeWindow.location.href).toEqual('http://new.org/'); expect(pushState).not.toHaveBeenCalled(); expect(replaceState).not.toHaveBeenCalled(); @@ -352,7 +352,7 @@ describe('browser', function() { sniffer.history = false; browser.url('http://new.org', true); - expect(locationReplace).toHaveBeenCalledWith('http://new.org'); + expect(locationReplace).toHaveBeenCalledWith('http://new.org/'); expect(pushState).not.toHaveBeenCalled(); expect(replaceState).not.toHaveBeenCalled(); @@ -945,7 +945,7 @@ describe('browser', function() { it('should not interfere with legacy browser url replace behavior', function() { inject(function($rootScope) { var current = fakeWindow.location.href; - var newUrl = 'notyet'; + var newUrl = 'http://notyet/'; sniffer.history = false; expect(historyEntriesLength).toBe(1); browser.url(newUrl, true);