Skip to content

Commit 295142e

Browse files
committed
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.
1 parent affcbad commit 295142e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/ngRoute/route.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,10 +586,10 @@ function $RouteProvider(){
586586
if (i === 0) {
587587
result.push(segment);
588588
} else {
589-
var segmentMatch = segment.match(/(\w+)(.*)/);
589+
var segmentMatch = segment.match(/(\w+)([\?|\*])?(.*)/);
590590
var key = segmentMatch[1];
591591
result.push(params[key]);
592-
result.push(segmentMatch[2] || '');
592+
result.push(segmentMatch[3] || '');
593593
delete params[key];
594594
}
595595
});

0 commit comments

Comments
 (0)