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

Commit 891acf4

Browse files
gkalpakpkozlowski-opensource
authored andcommitted
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 Closes #9827
1 parent 93552fe commit 891acf4

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
@@ -974,6 +974,29 @@ describe('$route', function() {
974974
});
975975

976976

977+
it('should properly interpolate optional and eager route vars ' +
978+
'when redirecting from path with trailing slash', function() {
979+
module(function($routeProvider) {
980+
$routeProvider.when('/foo/:id?/:subid?', {templateUrl: 'foo.html'});
981+
$routeProvider.when('/bar/:id*/:subid', {templateUrl: 'bar.html'});
982+
});
983+
984+
inject(function($location, $rootScope, $route) {
985+
$location.path('/foo/id1/subid2/');
986+
$rootScope.$digest();
987+
988+
expect($location.path()).toEqual('/foo/id1/subid2');
989+
expect($route.current.templateUrl).toEqual('foo.html');
990+
991+
$location.path('/bar/id1/extra/subid2/');
992+
$rootScope.$digest();
993+
994+
expect($location.path()).toEqual('/bar/id1/extra/subid2');
995+
expect($route.current.templateUrl).toEqual('bar.html');
996+
});
997+
});
998+
999+
9771000
it('should allow custom redirectTo function to be used', function() {
9781001
function customRedirectFn(routePathParams, path, search) {
9791002
expect(routePathParams).toEqual({id: 'id3'});

0 commit comments

Comments
 (0)