From 4412fe238f37f79a2017ee7b20ba089c0acd73e9 Mon Sep 17 00:00:00 2001 From: rrsivabalan Date: Wed, 4 Nov 2015 22:21:04 +0530 Subject: [PATCH] fix($location): ensure `$locationChangeSuccess` fires even if URL ends with `#` Closes #12175 Closes #13251 --- src/ng/location.js | 2 +- test/ng/locationSpec.js | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/ng/location.js b/src/ng/location.js index f575a653f916..3c91549b53b4 100644 --- a/src/ng/location.js +++ b/src/ng/location.js @@ -918,7 +918,7 @@ function $LocationProvider() { var oldUrl = $location.absUrl(); var oldState = $location.$$state; var defaultPrevented; - + newUrl = trimEmptyHash(newUrl); $location.$$parse(newUrl); $location.$$state = newState; diff --git a/test/ng/locationSpec.js b/test/ng/locationSpec.js index 1efe3396762f..8e1607c83146 100644 --- a/test/ng/locationSpec.js +++ b/test/ng/locationSpec.js @@ -2141,6 +2141,31 @@ describe('$location', function() { }) ); + it('should fire $locationChangeSuccess when browser location changes to URL which ends with #', + inject(function($location, $browser, $rootScope, $log) { + $location.url('/somepath'); + $rootScope.$apply(); + + expect($browser.url()).toEqual('http://server/#/somepath'); + expect($location.url()).toEqual('/somepath'); + + $rootScope.$on('$locationChangeStart', function(event, newUrl, oldUrl) { + $log.info('start', newUrl, oldUrl); + }); + $rootScope.$on('$locationChangeSuccess', function(event, newUrl, oldUrl) { + $log.info('after', newUrl, oldUrl); + }); + + $browser.url('http://server/#'); + $browser.poll(); + + expect($log.info.logs.shift()). + toEqual(['start', 'http://server/', 'http://server/#/somepath']); + expect($log.info.logs.shift()). + toEqual(['after', 'http://server/', 'http://server/#/somepath']); + }) + ); + it('should allow redirect during browser url change', inject(function($location, $browser, $rootScope, $log) { $rootScope.$on('$locationChangeStart', function(event, newUrl, oldUrl) {