fix($routeProvider): properly handle optional eager path named groups
Closes #14011
This commit is contained in:
committed by
Georgios Kalpakas
parent
9421674dad
commit
bf2a76d32f
@@ -213,9 +213,9 @@ function $RouteProvider() {
|
||||
|
||||
path = path
|
||||
.replace(/([().])/g, '\\$1')
|
||||
.replace(/(\/)?:(\w+)([\?\*])?/g, function(_, slash, key, option) {
|
||||
var optional = option === '?' ? option : null;
|
||||
var star = option === '*' ? option : null;
|
||||
.replace(/(\/)?:(\w+)(\*\?|[\?\*])?/g, function(_, slash, key, option) {
|
||||
var optional = (option === '?' || option === '*?') ? '?' : null;
|
||||
var star = (option === '*' || option === '*?') ? '*' : null;
|
||||
keys.push({ name: key, optional: !!optional });
|
||||
slash = slash || '';
|
||||
return ''
|
||||
|
||||
@@ -974,6 +974,32 @@ describe('$route', function() {
|
||||
});
|
||||
|
||||
|
||||
it('should properly process route params which are both eager and optional', function() {
|
||||
module(function($routeProvider) {
|
||||
$routeProvider.when('/foo/:param1*?/:param2', {templateUrl: 'foo.html'});
|
||||
});
|
||||
|
||||
inject(function($location, $rootScope, $route) {
|
||||
$location.path('/foo/bar1/bar2/bar3/baz');
|
||||
$rootScope.$digest();
|
||||
|
||||
expect($location.path()).toEqual('/foo/bar1/bar2/bar3/baz');
|
||||
expect($route.current.params.param1).toEqual('bar1/bar2/bar3');
|
||||
expect($route.current.params.param2).toEqual('baz');
|
||||
expect($route.current.templateUrl).toEqual('foo.html');
|
||||
|
||||
$location.path('/foo/baz');
|
||||
$rootScope.$digest();
|
||||
|
||||
expect($location.path()).toEqual('/foo/baz');
|
||||
expect($route.current.params.param1).toEqual(undefined);
|
||||
expect($route.current.params.param2).toEqual('baz');
|
||||
expect($route.current.templateUrl).toEqual('foo.html');
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should properly interpolate optional and eager route vars ' +
|
||||
'when redirecting from path with trailing slash', function() {
|
||||
module(function($routeProvider) {
|
||||
|
||||
Reference in New Issue
Block a user