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

Commit

Permalink
fix(ngRoute): remove unnecessary call to decodeURIComponent
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mllrjb authored and petebacondarwin committed Jul 15, 2014
1 parent 49b2a1c commit 1b77902
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 1 addition & 3 deletions src/ngRoute/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions test/ngRoute/routeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
}));
Expand Down

0 comments on commit 1b77902

Please sign in to comment.