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

Commit 0ff86c3

Browse files
theniksovojtajina
authored andcommitted
fix(routeProvider): parametrized routes do not match against locations that would not valorize each parameters.
1 parent 31f190d commit 0ff86c3

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/ngRoute/route.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ function $RouteProvider(){
177177
+ (optional ? '' : slash)
178178
+ '(?:'
179179
+ (optional ? slash : '')
180-
+ (star && '(.+)?' || '([^/]+)?') + ')'
180+
+ (star && '(.+?)' || '([^/]+)')
181+
+ (optional || '')
182+
+ ')'
181183
+ (optional || '');
182184
})
183185
.replace(/([\/$\*])/g, '\\$1');

test/ngRoute/routeSpec.js

+44
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,50 @@ describe('$route', function() {
331331
});
332332

333333

334+
it('should skip routes with incomplete params', function() {
335+
module(function($routeProvider) {
336+
$routeProvider
337+
.otherwise({template: 'other'})
338+
.when('/pages/:page/:comment*', {template: 'comment'})
339+
.when('/pages/:page', {template: 'page'})
340+
.when('/pages', {template: 'index'})
341+
.when('/foo/', {template: 'foo'})
342+
.when('/foo/:bar', {template: 'bar'})
343+
.when('/foo/:bar*/:baz', {template: 'baz'});
344+
});
345+
346+
inject(function($route, $location, $rootScope) {
347+
$location.url('/pages/');
348+
$rootScope.$digest();
349+
expect($route.current.template).toBe('index');
350+
351+
$location.url('/pages/page/');
352+
$rootScope.$digest();
353+
expect($route.current.template).toBe('page');
354+
355+
$location.url('/pages/page/1/');
356+
$rootScope.$digest();
357+
expect($route.current.template).toBe('comment');
358+
359+
$location.url('/foo/');
360+
$rootScope.$digest();
361+
expect($route.current.template).toBe('foo');
362+
363+
$location.url('/foo/bar/');
364+
$rootScope.$digest();
365+
expect($route.current.template).toBe('bar');
366+
367+
$location.url('/foo/bar/baz/');
368+
$rootScope.$digest();
369+
expect($route.current.template).toBe('baz');
370+
371+
$location.url('/something/');
372+
$rootScope.$digest();
373+
expect($route.current.template).toBe('other');
374+
});
375+
});
376+
377+
334378
describe('otherwise', function() {
335379

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

0 commit comments

Comments
 (0)