From 99f25050a34a0f0e2b0bdc63a55f38097f7098db Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Sun, 31 Oct 2010 02:11:50 +0200 Subject: Fixing issue #98 (infinite loop when location hash set empty) Added tests and fixed the issue. Closes #98 --- src/services.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/services.js') diff --git a/src/services.js b/src/services.js index 144f6177..fca4bca1 100644 --- a/src/services.js +++ b/src/services.js @@ -16,12 +16,15 @@ angularServiceInject("$document", function(window){ angularServiceInject("$location", function(browser) { var scope = this, location = {toString:toString, update:update, updateHash: updateHash}, - lastLocationHref = browser.getUrl(), + lastBrowserUrl = browser.getUrl(), + lastLocationHref, lastLocationHash; - browser.addPollFn(function(){ - if (lastLocationHref !== browser.getUrl()) { - update(lastLocationHref = browser.getUrl()); + browser.addPollFn(function() { + if (lastBrowserUrl != browser.getUrl()) { + update(lastBrowserUrl = browser.getUrl()); + lastLocationHref = location.href; + lastLocationHash = location.hash; scope.$eval(); } }); @@ -29,7 +32,8 @@ angularServiceInject("$location", function(browser) { this.$onEval(PRIORITY_FIRST, updateBrowser); this.$onEval(PRIORITY_LAST, updateBrowser); - update(lastLocationHref); + update(lastBrowserUrl); + lastLocationHref = location.href; lastLocationHash = location.hash; return location; @@ -137,8 +141,9 @@ angularServiceInject("$location", function(browser) { function updateBrowser() { updateLocation(); - if (location.href != lastLocationHref) { - browser.setUrl(lastLocationHref = location.href); + if (location.href != lastLocationHref) { + browser.setUrl(lastBrowserUrl = location.href); + lastLocationHref = location.href; lastLocationHash = location.hash; } } @@ -180,7 +185,7 @@ angularServiceInject("$location", function(browser) { var match = URL_MATCH.exec(href); if (match) { - loc.href = href.replace('#$', ''); + loc.href = href.replace(/#$/, ''); loc.protocol = match[1]; loc.host = match[3] || ''; loc.port = match[5] || DEFAULT_PORTS[loc.protocol] || _null; -- cgit v1.2.3