From 528f56a690295650f54eeb2238609446635c5db0 Mon Sep 17 00:00:00 2001 From: Jason Miller <jbradfordmiller@gmail.com> Date: Tue, 18 Feb 2014 16:26:00 -0700 Subject: [PATCH] fix(ngRoute): remove unnecessary call to decodeURIComponent Since `$location.$$path` is already decoded, doing an extra `decodeURIComponent` is both unnecessary and can cause problems. Specifically, if the path originally includes an encoded `%` (aka `%25`), then ngRoute will throw "URIError: URI malformed". Closes #6326 Closes #6327 --- src/ngRoute/route.js | 4 +--- test/ngRoute/routeSpec.js | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/ngRoute/route.js b/src/ngRoute/route.js index 1f992b695bfa..750a7f5ead20 100644 --- a/src/ngRoute/route.js +++ b/src/ngRoute/route.js @@ -468,9 +468,7 @@ function $RouteProvider(){ for (var i = 1, len = m.length; i < len; ++i) { var key = keys[i - 1]; - var val = 'string' == typeof m[i] - ? decodeURIComponent(m[i]) - : m[i]; + var val = m[i]; if (key && val) { params[key.name] = val; diff --git a/test/ngRoute/routeSpec.js b/test/ngRoute/routeSpec.js index 8584fb0c7909..072cf6bb8ab7 100644 --- a/test/ngRoute/routeSpec.js +++ b/test/ngRoute/routeSpec.js @@ -219,13 +219,13 @@ describe('$route', function() { expect($route.current).toBeUndefined(); })); - it('matches literal .', inject(function($route, $location, $rootScope) { + it('matches literal *', inject(function($route, $location, $rootScope) { $location.path('/$testX23/foo*(bar)/222'); $rootScope.$digest(); expect($route.current).toBeUndefined(); })); - it('matches literal *', inject(function($route, $location, $rootScope) { + it('matches literal .', inject(function($route, $location, $rootScope) { $location.path('/$test.23/foooo(bar)/222'); $rootScope.$digest(); expect($route.current).toBeUndefined(); @@ -238,7 +238,7 @@ describe('$route', function() { })); it('matches a URL with special chars', inject(function($route, $location, $rootScope) { - $location.path('/$test.23/foo*(bar)/222'); + $location.path('/$test.23/foo*(bar)/~!@#$%^&*()_+=-`'); $rootScope.$digest(); expect($route.current).toBeDefined(); }));