-
Notifications
You must be signed in to change notification settings - Fork 3k
Slash encoding #1645
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
Comments
I got around this issue by explicitly configuring the parameter types to 'any'. Behind the scenes, ui router wraps search parameters into ArrayTypes but will use the encode/decode callbacks for the wrapped type. By default, it treats query parameters as strings. And for some reason ( scratching my head, why you'd ever want to double encode the forward slash ) it will double encode forward slashes.
|
Hi, I'm sending in this: and on click I'm seeing on my browser url.com/editor/CBVPPYMD10.1017%252FS003329171400227X I'm also seeing this same doubly encoded string as the href attribute generated by ui-router on Inspect Element. My real doc id is CBVPPYMD10.1017/S003329171400227X I just updated to @Version v0.2.15 and I have latest angular (1.4) Thanks. |
Oh, I see that this is being addressed here? Is this supposed to be fixed? |
@tweinerpq #2071 won’t change the “double encoding” of the slash in the URL, however it will fix the decoding, so the encoded slash from the URL ( |
+1 The problem comes from UrlMatcherFactory.js:360. The value is encoded on line 338, and then that encoded value is passed to encodeURIComponent on line 360: /* 338 */ var encoded = param.type.encode(value);
// …
/* 360 */ encoded = map(encoded, encodeURIComponent).join('&' + name + '='); |
I have made some research on this. function valToString(val) { return val != null ? val.toString().replace(/\//g, "%2F") : val; }
function valFromString(val) { return val != null ? val.toString().replace(/%2F/g, "/") : val; }
var $types = {}, enqueue = true, typeQueue = [], injector, defaultTypes = {
string: {
encode: valToString,
decode: valFromString, This behavior was introduced in 3045e41 and 0c983a0 fixing #1119 |
Solution here: #1119 (comment) |
Not in Chrome, @zivc |
Is there any reason why one would ever want to encode the slash (via valToString) and then encodeURIComponent on top of that, either in parameters or in a path component? |
What I don't like is that the href is shown with an encoded slash when passing a url with a slash as a parameter to ui-sref: site.com/page%2Fhome. I feel like this is not good when search engines are crawling the website for links. |
Any update on this bug? It's causing me a few problems. It's not only that the slashes are double-encoded, but it make decoding them wrong, because by manually replacing those slashes you take them out of step with the rest of encoding/decoding. For example let's say this is URL: The proper way to encode it would be: But because of the manual slash encoding by uiRouter and then usage of Now when you try to decode the This might be a simple example, but in my case this is causing me a lot of problems with email confirmation tokens. |
We are experiencing a similar problem: One of the parameter in our routes is a URL, e.g. Pre-requisite reading: http://blog.lunatech.com/2009/02/03/what-every-web-developer-must-know-about-url-encoding I think the core of the problem is that we need to consider that we're inside the fragment part of the browser URL, e.g. On a regular (non AngularJS) link, it means you can have a valid fragment part like But within an AngularJS app you can't have that, because
What you really want is: So I suspect the solution is to encode/decode the values following the rules for URL fragment parts but to make an exception just for slashes. Not respecting the fragment rules may cause problems with other special chars ``/?:@-._~!$&'()*+,;=` . I think only the slash is special in our case. To add to the confusion,
Hope this helps! |
Same issue here. Slashes in query string parameters are getting double encoded when going through $state.go for example. C/L becomes C%252FL where it should be C%2FL |
This should be fixed in release 0.2.16+ We now encode slashes specially, using a custom escape character (tilde) |
Seems like this just makes an error less likely to happen by doing your own encoding with ~, while introducing another issue. What happens if ~2F is in a parameter? Then it will get decoded to a /. How come you guys aren't using encodeURIComponent? |
@fallXone because angular $location has special handling for splitting on '/' which causes encoded parameter values with slashes like See my analysis ticket: #2598 Note: if we weren't using |
url: 'products/{slugPath:.*}' |
Angular 1.6.7 introduced a change of how forward slashes are handled. This broke our current angular app which is using url: '{aliasUrl:any}'. Has this change broken any other apps? Temporarily we've reverted back to 1.6.6 to resolve the issue. |
Broke our app too, URLs get double-encoded ( |
Does anyone have any updates on this issue? It is breaking our site as well. |
Follow the angular repository for updates on this. Related angularjs 1.6.7 issues and prs:
|
So, has this been fixed in 1.6.8? |
The uirouter/angularjs test suite passes using angular 1.6.8 (it does not pass with 1.6.7) |
I am still getting the problem when trying to pass dates.
The following URL is generated:
This is my state provider code:
I am using the latest version of ui.router
The text was updated successfully, but these errors were encountered: