encodeUriSegment in resource encodes params, should be optional
When having a $resource and sending a param to be used in the url, it would be nice if there was an option not to encode it. OOB it encodes (in this case the "path") param before it's match agains the url. For example
// In SomeResourceName factory:
$resouce('/:path', { path: 'default.json' }, ...)
// Useing SomeResourceName
SomeResourceName.get({ path: 'game/mygame.json' })
This will result in a call to url "/game%2Fmygame.json" instead of "/game/mygame.json".
There's a quick-fix-workaround:
// In angular-resource.js and method encodeUriSegment
function encodeUriSegment(val) {
return encodeUriQuery(val, true).
replace(/%26/gi, '&').
replace(/%3D/gi, '=').
replace(/%2B/gi, '+').
replace(/%2F/gi, '/'); // <--- Add this line
}
I have no idea what will break, but as of know it works for me. One could also hijack the actions argument in ResourceFactory and pass a skip encode flag to the Route constructor's defaults argument to tell it to skip the encoding.
I was using an HTTP interceptor to transform URLs. It was working until I tested on IE11. Angular breaks on XHR requests to URLs including % in IE11. Not sure about IE10. Angular is supposed to support IE9+ (reference)
Guess I'm going back to the modified ngResource..
@connorbode --- dude, like it was mentioned in your issue, write a failing test case =) This path SHOULD already be covered, so there's two possibilities, either it's not covered and should be, or you're doing something to break this.
Lets find out which it is!
+1
+1
+1
Impossible to work with CouchDB and design-documents (_design/cafehub/_view/menu_items)
Can you guys +1 my pull request instead of this issue? It fixes the issue but has been generally ignored since its submission. https://github.com/angular/angular.js/pull/7940
+1 Really need this to interact with some legacy webservices which do not perform URLdecode
+1
There are definitely viable, useful circumstances where a user will want to disable the encoding of URL parameters (for instance, where you want to append to a base URL a path to a resource).
+1
+1
+1
+1
@toddb just FYI, your spec quote refers to the fragment part of a URL, i.e. the #foo/bar part, where escaping a slash is indeed not required or appropriate. But this bug is about escaping a slash in the main path part of the URL. In general, I don't think the RFC applies to this, how Angular's $resource service handles pattern matching and URL construction really doesn't concern the RFC much.
Not escaping slashes in a regular :param style parameter has the problem that it makes the pattern non-invertible. E.g. if you have /x/:param, and you allow generating /x/y/z for {param: 'y/z'}, the resulting /x/y/z will fail to parse against the URL pattern.
IMHO it might make sense to have a feature in URL patterns to accept a star pattern that eats slashes, e.g. "/:param1/:param2/*pathParam", where *pathParam would eat slashes in the URL. For * params, it'd then make sense to also accept slashes without escaping them.
@mprobst - you are quite correct that I was logging a bug only around the fragment. The code as I use it also affects the fragment. I am not using the $resource service but rather $location. If my memory serves me there are a couple of implementations of the uriSegment code.
The patch by @connorbode from a quick read will address the issue. Cheers
+1
+1
+1
+1
+1
+1