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 321d961a7430..1839fd0e17cf 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(); @@ -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'});