Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 0265bea

Browse files
committed
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
1 parent 7dc07ed commit 0265bea

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/ngRoute/route.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ function $RouteProvider() {
652652
if (i === 0) {
653653
result.push(segment);
654654
} else {
655-
var segmentMatch = segment.match(/(\w+)(.*)/);
655+
var segmentMatch = segment.match(/(\w+)(?:[?*])?(.*)/);
656656
var key = segmentMatch[1];
657657
result.push(params[key]);
658658
result.push(segmentMatch[2] || '');

test/ngRoute/routeSpec.js

+23
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,29 @@ describe('$route', function() {
944944
});
945945

946946

947+
it('should properly interpolate optional and eager route vars ' +
948+
'when redirecting from path with trailing slash', function() {
949+
module(function($routeProvider) {
950+
$routeProvider.when('/foo/:id?/:subid?', {templateUrl: 'foo.html'});
951+
$routeProvider.when('/bar/:id*/:subid', {templateUrl: 'bar.html'});
952+
});
953+
954+
inject(function($location, $rootScope, $route) {
955+
$location.path('/foo/id1/subid2/');
956+
$rootScope.$digest();
957+
958+
expect($location.path()).toEqual('/foo/id1/subid2');
959+
expect($route.current.templateUrl).toEqual('foo.html');
960+
961+
$location.path('/bar/id1/extra/subid2/');
962+
$rootScope.$digest();
963+
964+
expect($location.path()).toEqual('/bar/id1/extra/subid2');
965+
expect($route.current.templateUrl).toEqual('bar.html');
966+
});
967+
});
968+
969+
947970
it('should allow custom redirectTo function to be used', function() {
948971
function customRedirectFn(routePathParams, path, search) {
949972
expect(routePathParams).toEqual({id: 'id3'});

0 commit comments

Comments
 (0)