From 295142e472f436eda078fe9496dbad144a41ca1c Mon Sep 17 00:00:00 2001 From: Pasvaz Date: Sat, 11 Jan 2014 23:01:07 +0100 Subject: [PATCH 1/2] fix(ngRoute): wrong redirect to path containing named groups ending with star or question mark When the path contains optional parameters or special parameters the redirects to those routes are broken, the location will end with the relative encoded character. To reproduce the issue: * create a route with optional parameters, es. `$routeProvider.when('/profile/:userId?', ...)` * angular will add the automatic redirect with or without the trailing **/**, in this case `'/profile/:userId?/'` * point the browser to the redirect `http://localhost/#!/profile/0/`, you'll see the encoded `? (%3F)` at the end of the url: `http://localhost/#!/profile/0%3F` Happens also for the special parameters `*` and also for the opposite scenario, when the route has `/profile/:userId?/` and you browse the url `/profile/0`. It affects every redirect that uses the function interpolate. --- src/ngRoute/route.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ngRoute/route.js b/src/ngRoute/route.js index 34f3f9ec05f1..debdbab1c669 100644 --- a/src/ngRoute/route.js +++ b/src/ngRoute/route.js @@ -586,10 +586,10 @@ 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] || ''); + result.push(segmentMatch[3] || ''); delete params[key]; } }); From 6a1e2d5fbdd3d926d0a97e733ffd0819436ff141 Mon Sep 17 00:00:00 2001 From: Pasvaz Date: Wed, 22 Jan 2014 12:31:39 +0100 Subject: [PATCH 2/2] removed | from regexp --- src/ngRoute/route.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ngRoute/route.js b/src/ngRoute/route.js index debdbab1c669..cbef4caf7d12 100644 --- a/src/ngRoute/route.js +++ b/src/ngRoute/route.js @@ -586,7 +586,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[3] || '');