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

Commit f398e80

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 5f54934 commit f398e80

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
@@ -650,7 +650,7 @@ function $RouteProvider() {
650650
if (i === 0) {
651651
result.push(segment);
652652
} else {
653-
var segmentMatch = segment.match(/(\w+)(.*)/);
653+
var segmentMatch = segment.match(/(\w+)(?:[?*])?(.*)/);
654654
var key = segmentMatch[1];
655655
result.push(params[key]);
656656
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)