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

Commit 1b9e408

Browse files
gkalpakpkozlowski-opensource
authored andcommitted
fix($route): fix redirection with optional/eager params
Fixes #9742 Closes #10202
1 parent 7505d12 commit 1b9e408

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/ngRoute/route.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ function $RouteProvider(){
577577
if (i === 0) {
578578
result.push(segment);
579579
} else {
580-
var segmentMatch = segment.match(/(\w+)(.*)/);
580+
var segmentMatch = segment.match(/(\w+)(?:[?*])?(.*)/);
581581
var key = segmentMatch[1];
582582
result.push(params[key]);
583583
result.push(segmentMatch[2] || '');

test/ngRoute/routeSpec.js

+25-2
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,13 @@ describe('$route', function() {
219219
expect($route.current).toBeUndefined();
220220
}));
221221

222-
it('matches literal *', inject(function($route, $location, $rootScope) {
222+
it('matches literal .', inject(function($route, $location, $rootScope) {
223223
$location.path('/$testX23/foo*(bar)/222');
224224
$rootScope.$digest();
225225
expect($route.current).toBeUndefined();
226226
}));
227227

228-
it('matches literal .', inject(function($route, $location, $rootScope) {
228+
it('matches literal *', inject(function($route, $location, $rootScope) {
229229
$location.path('/$test.23/foooo(bar)/222');
230230
$rootScope.$digest();
231231
expect($route.current).toBeUndefined();
@@ -830,6 +830,29 @@ describe('$route', function() {
830830
});
831831

832832

833+
it('should properly interpolate optional and eager route vars ' +
834+
'when redirecting from path with trailing slash', function() {
835+
module(function($routeProvider) {
836+
$routeProvider.when('/foo/:id?/:subid?', {templateUrl: 'foo.html'});
837+
$routeProvider.when('/bar/:id*/:subid', {templateUrl: 'bar.html'});
838+
});
839+
840+
inject(function($location, $rootScope, $route) {
841+
$location.path('/foo/id1/subid2/');
842+
$rootScope.$digest();
843+
844+
expect($location.path()).toEqual('/foo/id1/subid2');
845+
expect($route.current.templateUrl).toEqual('foo.html');
846+
847+
$location.path('/bar/id1/extra/subid2/');
848+
$rootScope.$digest();
849+
850+
expect($location.path()).toEqual('/bar/id1/extra/subid2');
851+
expect($route.current.templateUrl).toEqual('bar.html');
852+
});
853+
});
854+
855+
833856
it('should allow custom redirectTo function to be used', function() {
834857
function customRedirectFn(routePathParams, path, search) {
835858
expect(routePathParams).toEqual({id: 'id3'});

0 commit comments

Comments
 (0)