From 21ffa1152ac61d77783aa8d40d3c6cd637807303 Mon Sep 17 00:00:00 2001 From: Georgios Kalpakas Date: Wed, 29 Oct 2014 18:16:24 +0200 Subject: [PATCH 1/2] test($route): fix test names --- test/ngRoute/routeSpec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/ngRoute/routeSpec.js b/test/ngRoute/routeSpec.js index 321d961a7430..b5221be730f1 100644 --- a/test/ngRoute/routeSpec.js +++ b/test/ngRoute/routeSpec.js @@ -326,13 +326,13 @@ describe('$route', function() { expect($route.current).toBeUndefined(); })); - it('matches literal *', inject(function($route, $location, $rootScope) { + it('matches literal .', inject(function($route, $location, $rootScope) { $location.path('/$testX23/foo*(bar)/222'); $rootScope.$digest(); expect($route.current).toBeUndefined(); })); - it('matches literal .', inject(function($route, $location, $rootScope) { + it('matches literal *', inject(function($route, $location, $rootScope) { $location.path('/$test.23/foooo(bar)/222'); $rootScope.$digest(); expect($route.current).toBeUndefined(); From b414e5e746a2dfb6998abafb54e89bef2f3a0056 Mon Sep 17 00:00:00 2001 From: Georgios Kalpakas Date: Wed, 29 Oct 2014 18:48:04 +0200 Subject: [PATCH 2/2] fix($route): fix redirection with optional/eager params Previously, when (automatically) redirecting from path that fetured a trailing slash and optional or "eager" parameters, the resulting path would (incorrectly) contain the special characters (`?`,`*`) along with the parameter values. Closes #9819 --- src/ngRoute/route.js | 2 +- test/ngRoute/routeSpec.js | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/ngRoute/route.js b/src/ngRoute/route.js index 5b765501cda1..7e59457a0381 100644 --- a/src/ngRoute/route.js +++ b/src/ngRoute/route.js @@ -652,7 +652,7 @@ function $RouteProvider() { if (i === 0) { result.push(segment); } else { - var segmentMatch = segment.match(/(\w+)(.*)/); + var segmentMatch = segment.match(/(\w+)(?:[?*])?(.*)/); var key = segmentMatch[1]; result.push(params[key]); result.push(segmentMatch[2] || ''); diff --git a/test/ngRoute/routeSpec.js b/test/ngRoute/routeSpec.js index b5221be730f1..1839fd0e17cf 100644 --- a/test/ngRoute/routeSpec.js +++ b/test/ngRoute/routeSpec.js @@ -974,6 +974,29 @@ describe('$route', function() { }); + it('should properly interpolate optional and eager route vars ' + + 'when redirecting from path with trailing slash', function() { + module(function($routeProvider) { + $routeProvider.when('/foo/:id?/:subid?', {templateUrl: 'foo.html'}); + $routeProvider.when('/bar/:id*/:subid', {templateUrl: 'bar.html'}); + }); + + inject(function($location, $rootScope, $route) { + $location.path('/foo/id1/subid2/'); + $rootScope.$digest(); + + expect($location.path()).toEqual('/foo/id1/subid2'); + expect($route.current.templateUrl).toEqual('foo.html'); + + $location.path('/bar/id1/extra/subid2/'); + $rootScope.$digest(); + + expect($location.path()).toEqual('/bar/id1/extra/subid2'); + expect($route.current.templateUrl).toEqual('bar.html'); + }); + }); + + it('should allow custom redirectTo function to be used', function() { function customRedirectFn(routePathParams, path, search) { expect(routePathParams).toEqual({id: 'id3'});