-
Notifications
You must be signed in to change notification settings - Fork 27.5k
fix(ngRoute): wrong redirect to paths containing optional or special parameters #5746
Conversation
…ith 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.
@@ -586,10 +586,10 @@ function $RouteProvider(){ | |||
if (i === 0) { | |||
result.push(segment); | |||
} else { | |||
var segmentMatch = segment.match(/(\w+)(.*)/); | |||
var segmentMatch = segment.match(/(\w+)([\?|\*])?(.*)/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need the pipe in the square brackets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it was a third special operator because it was used in the function pathRegExp, the part of code you have just updated with the #5920
I'll remove it as soon as I'll be at my pc.
Could you show a test case which fails without this change? I'm just trying to wrap my head around what the issue is --- NVM just read your explanation, makes sense. Thanks! |
we need a unit test for this change. |
I stumbled over the same problem. There's a small problem with your fix here too and so I rewrote the interpolation function and added a test case: #8200 |
When the redirect path contains optional or special parameters the interpolation function misses to remove them. This is also the case for the auto-generated redirection where a slash is appended or removed to a route. Change the way parameters are interpolated in a string. Remove undefined optional named groups and properly prepend a slash in case the named group was starting with one. Related to angular#5746.
When the redirect path contains optional or special parameters the interpolation function misses to remove them. This is also the case for the auto-generated redirection where a slash is appended or removed to a route. Change the way parameters are interpolated in a string. Remove undefined optional named groups and properly prepend a slash in case the named group was starting with one. Related to angular#5746.
When the redirect path contains optional or special parameters the interpolation function misses to remove them. This is also the case for the auto-generated redirection where a slash is appended or removed to a route. Change the way parameters are interpolated in a string. Remove undefined optional named groups and properly prepend a slash in case the named group was starting with one. Related to angular#5746.
When the redirect path contains optional or special parameters the interpolation function misses to remove them. This is also the case for the auto-generated redirection where a slash is appended or removed to a route. Change the way parameters are interpolated in a string. Remove undefined optional named groups and properly prepend a slash in case the named group was starting with one. Related to angular#5746.
02dc2aa
to
fd2d6c0
Compare
cad9560
to
f294244
Compare
e8dc429
to
e83fab9
Compare
4dd5a20
to
998c61c
Compare
This has been fixed by #9827. |
Indeed, thnx @gkalpak ! |
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:
$routeProvider.when('/profile/:userId?', ...)
'/profile/:userId?/'
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 the ending / (/profile/:userId?/
) and you browse the url without slash/profile/0
. It affects every redirect that uses the function interpolate in combination with special parameters.