From 9ae4f2a44c2cedb960f8480eba5b669a2ef636a5 Mon Sep 17 00:00:00 2001 From: Sam Millar Date: Wed, 27 Aug 2014 12:42:42 +0100 Subject: [PATCH] fix(ngRoute): change interpolation to support globbed routes Update regex so interpolation of an eager path segment does not leave behind a *. --- src/ngRoute/route.js | 2 +- test/ngRoute/routeSpec.js | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/ngRoute/route.js b/src/ngRoute/route.js index 53b1927d6ad5..d36e3a06ec13 100644 --- a/src/ngRoute/route.js +++ b/src/ngRoute/route.js @@ -611,7 +611,7 @@ function $RouteProvider(){ if (i === 0) { result.push(segment); } else { - var segmentMatch = segment.match(/(\w+)(.*)/); + var segmentMatch = segment.match(/(\w+)\*?(.*)/); var key = segmentMatch[1]; result.push(params[key]); result.push(segmentMatch[2] || ''); diff --git a/test/ngRoute/routeSpec.js b/test/ngRoute/routeSpec.js index 5dcf96edcb32..6a429337aa69 100644 --- a/test/ngRoute/routeSpec.js +++ b/test/ngRoute/routeSpec.js @@ -1175,6 +1175,33 @@ describe('$route', function() { }); + it('should support globbed route updating', function() { + module(function($routeProvider) { + $routeProvider.when('/bar/:foo*', {}); + $routeProvider.when('/baz/:foo*/edit', {}); + }); + + inject(function($rootScope, $route, $location, $routeParams) { + $location.path('/bar/multi/segment/path'); + $rootScope.$digest(); + expect($routeParams).toEqual({foo: 'multi/segment/path'}); + $route.updateParams({foo: 'new'}); + $rootScope.$digest(); + expect($routeParams).toEqual({foo: 'new'}); + $location.path('/baz/multi/segment/path/edit'); + + $rootScope.$digest(); + expect($routeParams).toEqual({foo: 'multi/segment/path'}); + $route.updateParams({foo: 'new'}); + $rootScope.$digest(); + expect($routeParams).toEqual({foo: 'new'}); + $route.updateParams({foo: 'new/multi'}); + $rootScope.$digest(); + expect($routeParams).toEqual({foo: 'new/multi'}); + }); + }); + + it('should complain if called without an existing route', inject(function($route) { expect($route.updateParams).toThrowMinErr('ngRoute', 'norout'); }));