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

Commit

Permalink
fix(routeProvider): parametrized routes do not match against location…
Browse files Browse the repository at this point in the history
…s that would not valorize each parameters.
  • Loading branch information
thenikso authored and vojtajina committed Oct 4, 2013
1 parent 31f190d commit 0ff86c3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ngRoute/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ function $RouteProvider(){
+ (optional ? '' : slash)
+ '(?:'
+ (optional ? slash : '')
+ (star && '(.+)?' || '([^/]+)?') + ')'
+ (star && '(.+?)' || '([^/]+)')
+ (optional || '')
+ ')'
+ (optional || '');
})
.replace(/([\/$\*])/g, '\\$1');
Expand Down
44 changes: 44 additions & 0 deletions test/ngRoute/routeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,50 @@ describe('$route', function() {
});


it('should skip routes with incomplete params', function() {
module(function($routeProvider) {
$routeProvider
.otherwise({template: 'other'})
.when('/pages/:page/:comment*', {template: 'comment'})
.when('/pages/:page', {template: 'page'})
.when('/pages', {template: 'index'})
.when('/foo/', {template: 'foo'})
.when('/foo/:bar', {template: 'bar'})
.when('/foo/:bar*/:baz', {template: 'baz'});
});

inject(function($route, $location, $rootScope) {
$location.url('/pages/');
$rootScope.$digest();
expect($route.current.template).toBe('index');

$location.url('/pages/page/');
$rootScope.$digest();
expect($route.current.template).toBe('page');

$location.url('/pages/page/1/');
$rootScope.$digest();
expect($route.current.template).toBe('comment');

$location.url('/foo/');
$rootScope.$digest();
expect($route.current.template).toBe('foo');

$location.url('/foo/bar/');
$rootScope.$digest();
expect($route.current.template).toBe('bar');

$location.url('/foo/bar/baz/');
$rootScope.$digest();
expect($route.current.template).toBe('baz');

$location.url('/something/');
$rootScope.$digest();
expect($route.current.template).toBe('other');
});
});


describe('otherwise', function() {

it('should handle unknown routes with "otherwise" route definition', function() {
Expand Down

0 comments on commit 0ff86c3

Please sign in to comment.