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.
+1
+1
You can use the same syntaxe like in the ui-router lib : http://angular-ui.github.io/ui-router/site/#/api/ui.router.util.type:UrlMatcher
+1
it also happens in location
:+1:
+1
I'm current doing a decode in order to send my original url to backend
.factory('decodeUriSegment', () => {
return (url) => {
return url.replace(/@/g, '%40')
.replace(/:/g, '%3A')
.replace(/\$/g, '%24')
.replace(/,/g, '%2C')
.replace(/\+/g, '%20');
};
});
+1
+1
app.config(function($resourceProvider) {
$resourceProvider.defaults.stripTrailingSlashes = false;
});
https://github.com/angular/angular.js/pull/5560
+1
i'm getting this error in angularjs $resource service Error: encodeUriSegment is not a function
@ibrahim89, make sure you use the same version of angular and angular-resource.
@gkalpak, thank you !!
my error is solved