-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
url encode stateparams #1119
Comments
Did you ever get anywhere with this? Having the same issue |
Can I see your state definitions? Does this work for querystring params but not path params? |
Somehow this bugfix introduced some new issues. When transitioning to a state with |
Doesn't this encode to "%252F" which is valid encoded in a url? |
I should mention why it encodes / to %2F, then passes to encodeURIComponent. If you run $location.url("/foo/%2F"), the slash is automatically decoded and appears in the browser bar as "/foo//" which is the same as the original behavior. Encoding the slash before running the string through encodeURIComponent is necessary to get the slash encoded into the url parameter.
|
Indeed it encodes to ´%252F´ within the URL if one of the parameters contains a What is the difference in your example? As you write twice |
I had more time to look at the issue and came across the In my use case the last parameter of the URL contains a path which may have more than one |
Thank you for checking, that is likely the issue |
Thanks for fixing the issue. Actually my problems are almost the same as #1557. I have a URL like the following |
Custom type, cool :) |
@christopherthielen I think there is one scenario which is still broken... or atleast, I can't get it working... I have objects which have a .state('base.list'
url: '/list?page&limit'
)
.state('base.list.item',
url: '/{item_id:(?:[^/]+\/[^/]+)}'
) So, the url constructed by the ui-sref for
... which does transition to the correct state, but when I reload the page, the regex match for the |
And as far as I remember, it was working perfectly in 0.2.11 |
@kumarharsh yeah that's a corner case I didn't think about. You don't actually need a regexp for item_id, now that the "string" parameter Type (the default type) encodes the slashes. just use If you really don't want the slash encoded for you, register a custom type with your regexp and declare item_id to be your custom type, i.e.,
|
I also needed a state parameter which is not URI encoded. Perhaps this should be included by default.. Here's my solution (in TypeScript)
|
This is awesome, thanks for the solution with the urlMatcher! |
@panuhorsmalahti great, thank you very much! |
Is this supposed to work with queryString parameters as well? I've tried the custom types with |
@martin-brennan-csnet yes, it is expected to work for query parameters too. |
@christopherthielen I appear to have a similar issue to @martin-brennan-csnet. Registering a custom type for my /route/{url:nonURIEncoded} parameter works a treat, but as a queryString parameter even though a call is made to my custom types 'encode' method, the forward slashes are still being converted to %2F when I call $state.go('state', {url: 'http://someurl/somepath'}) - am I missing something else here? Cheers! Ben |
I still can't get this to work. Am I missing something? Here's a quick plunk showing the problem: |
@nateabele sweet, nicely done. I'm not sure I understand your request however; would you like me to write a test for #2218? I'm not using 1.0 nor am I familiar with TypeScript yet, so I don't know possible that is. Or did you mean I should write an equivalent feature for 0.2.x (including tests)? That I could do! |
Yes.
The test suite & build setup are identical. You don't need to know anything about TypeScript. Just follow the contributor guidelines and add a failing test for a type with Let me know if you need help or have other questions. |
It this issue is fixed in latest release. If yes, then how i have to use it in defining ui routes. Bz i am getting the same issue with angular 1.4.7 & ui-router 0.2.15 |
Note that since 0.2.15 ui-router provides a type called |
@drothlis Unfortunately using 0.2.15 and Edit: to clarify, this issue was fixed by @nateabele in #2218, but only for v1.0.X. For older versions, i.e. v0.2.X, it remains unresolved. I think this is what @gonzoyumo's commit (gonzoyumo@c7f07e3) aims to resolve, but I suspect his commit won't get merged until proper tests are added. |
@mismith I see, there are several subtly different issues here.
(3) was broken because slashes were double-encoded in one direction and single-decoded in the other direction. Using the custom type (or (1) Still happens according to your plunkr. In my use case ( Honestly I can't tell which of the various github issues is supposed to track which of the above problems, but at least for my use case, I can confirm that Thanks for the info, the plunkr, and the link to the new |
@drothlis I am using "url: '/search/*path'". How can i use "any" with dynamic path? |
I should add that somewhere between 0.2.13 and 0.2.15, ui-router broke querystring components with slashes. In 0.2.13 you could have a state like this:
In 0.2.15 that will no longer work if the parameter values have slashes in them: the encode/decode round trip will give back a different result than the original value, just like it was already broken for path components in 0.2.13. In 0.2.15 you will have to use the
|
Thanks for your patience. Please build off |
Okay, so my particular case is that I am passing a url for redirect_url in OAuth. This is how it encodes:
My current work around is to decode it twice before I do any further processing with it. Here it is after first decode:
After the second decode:
@christopherthielen I tried that commit, and it doesn't seem to be different except for the difference using
|
@moneytree-doug urlencoding of the slashes was the root of the problem, which caused edge cases. I switched away from urlencoding slashes to a custom encoding that the browser cannot pre-process without our knowledge. Since I am not familiar with the OAuth flow, can you explain how your url parameter works through your workflow, and how the fix from 02e9866 is not helping? The goal for ui-router is to allow parameter values including path parameters to have encoded slashes, to allow path parameters to be in the middle of the path, and to be encoded/decoded bi-directionally (allowing a url with slashes in parameters to be bookmarked) As far as I can tell, we now perform this encoding properly. Slashes should encode to |
@christopherthielen I just upgraded from 0.2.15 to 0.2.18 and got this problem when using OAuth.. the slashes in the 0.2.15 - works!
0.2.18
this PR #2071 is already in 0.2.18 I think? I used
|
@lpsBetty I had a similar situation. You should expect the tilde after upgrading to 0.2.18. I ran into tons of headaches with this issue in the versions before and I had monkey patches, so I had tests around the encoding part until the fix came out. I am also doing OAuth, and I have migrated it safely. Your URL in the browser will definitely have a tilde, and this is fine and is expected. However, when you access it in your application code, ui-router will properly decode it in the Correct me if I misunderstood. |
thanks all about the comments and patience. I followed this issue to find a way to avoid encoding url but what I got was avoid encoding slashes!! my problem is the non-Latin chars. they're still being encoded. for example Arabic, Hebrew, Farsi etc. for example consider I have a HTML like this :
which will be compiled to:
on StackOverflow: is it possible to avoid that? |
@dkrugman Why is there no |
@moneytree-doug he has Html5Mode equal to True https://docs.angularjs.org/api/ng/provider/$locationProvider |
Closes angular-ui#2339 Closes angular-ui#2172 Closes angular-ui#2250 Closes angular-ui#1119
My issue may have been different, but I was happy to find and I had success with finally seeing the forward slash when writing the slugPath rather than |
Also note we support non-encoded param types in 1.0, via |
@majew7 Thanks! |
@fabiosussetto BIG THANKS MAN!!!!!! |
hey @fabiosussetto! I have another problem when I need to use param as query param. Can u please help to understand what I need to do to fix it? |
If i pass a string like
/default
to$stateParams
, it seems to mess up the routing:While the controller is invoked, the url is unable to switch to.
when i encode the value before passing it to $stateparams, it works.
however, ui-router should take care of doing the encoding/decoding for me.
The text was updated successfully, but these errors were encountered: