mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-14 17:53:11 +00:00
fix($location): prevent infinite digest error in IE7
Refactored `replacedUrl` to store the new URL on both `location.replace` and setting `location.href` directly to handle delays in the actual location value change in IE. Closes #2802
This commit is contained in:
parent
78a5889bc6
commit
d70711481e
2 changed files with 31 additions and 8 deletions
|
|
@ -125,7 +125,7 @@ function Browser(window, document, $log, $sniffer) {
|
||||||
|
|
||||||
var lastBrowserUrl = location.href,
|
var lastBrowserUrl = location.href,
|
||||||
baseElement = document.find('base'),
|
baseElement = document.find('base'),
|
||||||
replacedUrl = null;
|
newLocation = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name ng.$browser#url
|
* @name ng.$browser#url
|
||||||
|
|
@ -163,21 +163,20 @@ function Browser(window, document, $log, $sniffer) {
|
||||||
baseElement.attr('href', baseElement.attr('href'));
|
baseElement.attr('href', baseElement.attr('href'));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
newLocation = url;
|
||||||
if (replace) {
|
if (replace) {
|
||||||
location.replace(url);
|
location.replace(url);
|
||||||
replacedUrl = url;
|
|
||||||
} else {
|
} else {
|
||||||
location.href = url;
|
location.href = url;
|
||||||
replacedUrl = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
// getter
|
// getter
|
||||||
} else {
|
} else {
|
||||||
// - the replacedUrl is a workaround for an IE8-9 issue with location.replace method that doesn't update
|
// - newLocation is a workaround for an IE7-9 issue with location.replace and location.href
|
||||||
// location.href synchronously
|
// methods not updating location.href synchronously.
|
||||||
// - the replacement is a workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=407172
|
// - the replacement is a workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=407172
|
||||||
return replacedUrl || location.href.replace(/%27/g,"'");
|
return newLocation || location.href.replace(/%27/g,"'");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -185,6 +184,7 @@ function Browser(window, document, $log, $sniffer) {
|
||||||
urlChangeInit = false;
|
urlChangeInit = false;
|
||||||
|
|
||||||
function fireUrlChange() {
|
function fireUrlChange() {
|
||||||
|
newLocation = null;
|
||||||
if (lastBrowserUrl == self.url()) return;
|
if (lastBrowserUrl == self.url()) return;
|
||||||
|
|
||||||
lastBrowserUrl = self.url();
|
lastBrowserUrl = self.url();
|
||||||
|
|
|
||||||
|
|
@ -287,7 +287,7 @@ describe('browser', function() {
|
||||||
it('should default path in cookie to "" (empty string)', function () {
|
it('should default path in cookie to "" (empty string)', function () {
|
||||||
browser.cookies('cookie', 'bender');
|
browser.cookies('cookie', 'bender');
|
||||||
// This only fails in Safari and IE when cookiePath returns undefined
|
// This only fails in Safari and IE when cookiePath returns undefined
|
||||||
// Where it now succeeds since baseHref return '' instead of undefined
|
// Where it now succeeds since baseHref return '' instead of undefined
|
||||||
expect(document.cookie).toEqual('cookie=bender');
|
expect(document.cookie).toEqual('cookie=bender');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -535,9 +535,32 @@ describe('browser', function() {
|
||||||
fakeWindow.setTimeout.flush();
|
fakeWindow.setTimeout.flush();
|
||||||
expect(callback).toHaveBeenCalledWith('http://server.new');
|
expect(callback).toHaveBeenCalledWith('http://server.new');
|
||||||
|
|
||||||
|
callback.reset();
|
||||||
|
|
||||||
fakeWindow.fire('popstate');
|
fakeWindow.fire('popstate');
|
||||||
fakeWindow.fire('hashchange');
|
fakeWindow.fire('hashchange');
|
||||||
expect(callback).toHaveBeenCalledOnce();
|
expect(callback).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('after an initial location change by browser.url method when neither history nor hashchange supported', function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
sniffer.history = false;
|
||||||
|
sniffer.hashchange = false;
|
||||||
|
browser.url("http://server.current");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fire callback with the correct URL on location change outside of angular', function() {
|
||||||
|
browser.onUrlChange(callback);
|
||||||
|
|
||||||
|
fakeWindow.location.href = 'http://server.new';
|
||||||
|
fakeWindow.setTimeout.flush();
|
||||||
|
expect(callback).toHaveBeenCalledWith('http://server.new');
|
||||||
|
|
||||||
|
fakeWindow.fire('popstate');
|
||||||
|
fakeWindow.fire('hashchange');
|
||||||
|
expect(callback).toHaveBeenCalledOnce();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not fire urlChange if changed by browser.url method (polling)', function() {
|
it('should not fire urlChange if changed by browser.url method (polling)', function() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue