From 0ff86c323359fba1a60bacab178e3c68528f8e1f Mon Sep 17 00:00:00 2001 From: Nicola Peduzzi Date: Tue, 6 Aug 2013 17:35:48 +0200 Subject: [PATCH] fix(routeProvider): parametrized routes do not match against locations that would not valorize each parameters. --- src/ngRoute/route.js | 4 +++- test/ngRoute/routeSpec.js | 44 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/ngRoute/route.js b/src/ngRoute/route.js index cd911adab9c1..8a6dacd4e7c6 100644 --- a/src/ngRoute/route.js +++ b/src/ngRoute/route.js @@ -177,7 +177,9 @@ function $RouteProvider(){ + (optional ? '' : slash) + '(?:' + (optional ? slash : '') - + (star && '(.+)?' || '([^/]+)?') + ')' + + (star && '(.+?)' || '([^/]+)') + + (optional || '') + + ')' + (optional || ''); }) .replace(/([\/$\*])/g, '\\$1'); diff --git a/test/ngRoute/routeSpec.js b/test/ngRoute/routeSpec.js index ae9883a29972..bd7966e1c7c9 100644 --- a/test/ngRoute/routeSpec.js +++ b/test/ngRoute/routeSpec.js @@ -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() {