From c6392616ea5245bd0d2f77dded0b948d9e2637c8 Mon Sep 17 00:00:00 2001 From: Martin Probst Date: Mon, 14 Jan 2013 20:01:51 +0100 Subject: fix($route): support route params not separated with slashes. Commit 773ac4a broke support for route parameters that are not seperated from other route parts by slashes, which this change fixes. It also adds some documentation about path parameters to the when() method and escapes all regular expression special characters in the URL, not just some. --- test/ng/routeParamsSpec.js | 12 ++++++++++++ test/ng/routeSpec.js | 32 ++++++++++++++++++++++---------- 2 files changed, 34 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/ng/routeParamsSpec.js b/test/ng/routeParamsSpec.js index 07c6d4f7..52fe8d2a 100644 --- a/test/ng/routeParamsSpec.js +++ b/test/ng/routeParamsSpec.js @@ -29,4 +29,16 @@ describe('$routeParams', function() { expect($routeParams).toEqual({bar:'barvalue', foo:'foovalue'}); }); }); + + it('should support route params not preceded by slashes', function() { + module(function($routeProvider) { + $routeProvider.when('/bar:barId/foo:fooId/', {}); + }); + + inject(function($rootScope, $route, $location, $routeParams) { + $location.path('/barbarvalue/foofoovalue/'); + $rootScope.$digest(); + expect($routeParams).toEqual({barId: 'barvalue', fooId: 'foovalue'}); + }); + }); }); diff --git a/test/ng/routeSpec.js b/test/ng/routeSpec.js index 52fffa40..852f97b5 100644 --- a/test/ng/routeSpec.js +++ b/test/ng/routeSpec.js @@ -82,28 +82,40 @@ describe('$route', function() { }); - it('should match a route that contains special chars in the path', function() { - module(function($routeProvider) { - $routeProvider.when('/$test.23/foo(bar)/:baz', {templateUrl: 'test.html'}); - }); - inject(function($route, $location, $rootScope) { + describe('should match a route that contains special chars in the path', function() { + beforeEach(module(function($routeProvider) { + $routeProvider.when('/$test.23/foo*(bar)/:baz', {templateUrl: 'test.html'}); + })); + it('matches the full path', inject(function($route, $location, $rootScope) { $location.path('/test'); $rootScope.$digest(); expect($route.current).toBeUndefined(); + })); - $location.path('/$testX23/foo(bar)/222'); + it('matches literal .', inject(function($route, $location, $rootScope) { + $location.path('/$testX23/foo*(bar)/222'); $rootScope.$digest(); expect($route.current).toBeUndefined(); + })); - $location.path('/$test.23/foo(bar)/222'); + it('matches literal *', inject(function($route, $location, $rootScope) { + $location.path('/$test.23/foooo(bar)/222'); $rootScope.$digest(); - expect($route.current).toBeDefined(); + expect($route.current).toBeUndefined(); + })); - $location.path('/$test.23/foo\\(bar)/222'); + it('treats backslashes normally', inject(function($route, $location, $rootScope) { + $location.path('/$test.23/foo*\\(bar)/222'); $rootScope.$digest(); expect($route.current).toBeUndefined(); - }); + })); + + it('matches a URL with special chars', inject(function($route, $location, $rootScope) { + $location.path('/$test.23/foo*(bar)/222'); + $rootScope.$digest(); + expect($route.current).toBeDefined(); + })); }); -- cgit v1.2.3