Skip to content

Commit

Permalink
fix($location): prevent redirects on url change in <=IE9
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisirhc committed Sep 24, 2014
1 parent 729c238 commit 41bb66d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ng/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ function Browser(window, document, $log, $sniffer) {

function fireUrlChange() {
newLocation = null;
checkUrlChange();
}

function checkUrlChange() {
if (lastBrowserUrl == self.url()) return;

lastBrowserUrl = self.url();
Expand Down Expand Up @@ -239,7 +243,7 @@ function Browser(window, document, $log, $sniffer) {
* Needs to be exported to be able to check for changes that have been done in sync,
* as hashchange/popstate events fire in async.
*/
self.$$checkUrlChange = fireUrlChange;
self.$$checkUrlChange = checkUrlChange;

//////////////////////////////////////////////////////////////
// Misc API
Expand Down
23 changes: 23 additions & 0 deletions test/ng/browserSpecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,29 @@ describe('browser', function() {
expect($location.path()).toBe('/someTestHash');
});
});

});

describe('integration test with $rootScope', function() {

beforeEach(module(function($provide, $locationProvider) {
$provide.value('$browser', browser);
browser.pollFns = [];
}));

it('should not interfere with legacy browser url replace behavior', function() {
inject(function($rootScope) {
var current = fakeWindow.location.href;
var newUrl = 'notyet';
sniffer.history = false;
browser.url(newUrl, true);
expect(browser.url()).toBe(newUrl);
$rootScope.$digest();
expect(browser.url()).toBe(newUrl);
expect(fakeWindow.location.href).toBe(current);
});
});

});

});

0 comments on commit 41bb66d

Please sign in to comment.