Skip to content

Commit 35d393f

Browse files
committed
fixing code review comments and adding UT angular#12175
1 parent 0d96995 commit 35d393f

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/ng/location.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -918,16 +918,16 @@ function $LocationProvider() {
918918
var oldUrl = $location.absUrl();
919919
var oldState = $location.$$state;
920920
var defaultPrevented;
921-
921+
var trimNewUrl = trimEmptyHash(newUrl);
922922
$location.$$parse(newUrl);
923923
$location.$$state = newState;
924924

925-
defaultPrevented = $rootScope.$broadcast('$locationChangeStart', newUrl, oldUrl,
925+
defaultPrevented = $rootScope.$broadcast('$locationChangeStart', trimNewUrl, oldUrl,
926926
newState, oldState).defaultPrevented;
927927

928928
// if the location was changed by a `$locationChangeStart` handler then stop
929929
// processing this location change
930-
if ($location.absUrl() !== newUrl) return;
930+
if ($location.absUrl() !== trimNewUrl) return;
931931

932932
if (defaultPrevented) {
933933
$location.$$parse(oldUrl);

test/ng/locationSpec.js

+25
Original file line numberDiff line numberDiff line change
@@ -2141,6 +2141,31 @@ describe('$location', function() {
21412141
})
21422142
);
21432143

2144+
it('should fire $locationChangeSuccess when browser location changes to URL which ends with #',
2145+
inject(function($location, $browser, $rootScope, $log) {
2146+
$location.url('/somepath');
2147+
$rootScope.$apply();
2148+
2149+
expect($browser.url()).toEqual('http://server/#/somepath');
2150+
expect($location.url()).toEqual('/somepath');
2151+
2152+
$rootScope.$on('$locationChangeStart', function(event, newUrl, oldUrl) {
2153+
$log.info('start', newUrl, oldUrl);
2154+
});
2155+
$rootScope.$on('$locationChangeSuccess', function(event, newUrl, oldUrl) {
2156+
$log.info('after', newUrl, oldUrl);
2157+
});
2158+
2159+
$browser.url('http://server/#');
2160+
$browser.poll();
2161+
2162+
expect($log.info.logs.shift()).
2163+
toEqual(['start', 'http://server/', 'http://server/#/somepath']);
2164+
expect($log.info.logs.shift()).
2165+
toEqual(['after', 'http://server/', 'http://server/#/somepath']);
2166+
})
2167+
);
2168+
21442169
it('should allow redirect during browser url change',
21452170
inject(function($location, $browser, $rootScope, $log) {
21462171
$rootScope.$on('$locationChangeStart', function(event, newUrl, oldUrl) {

0 commit comments

Comments
 (0)