Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

stripTrailingSlashes not working? #15404

Closed
davidanaya opened this issue Nov 17, 2016 · 2 comments
Closed

stripTrailingSlashes not working? #15404

davidanaya opened this issue Nov 17, 2016 · 2 comments

Comments

@davidanaya
Copy link

davidanaya commented Nov 17, 2016

Hi

I'm having some problems with the property stripTrailingSlashes in angular $resource.
Maybe I'm missunderstanding what this is aimed to, but I've tried to use it to get rid of '%2F' in my urls with no success.

I've a plunkr to ilustrate what I want to do.

I'm trying to access a json file through a URL and in my plunkr it's actually working, but if I check the network tab in the console I can see the URL for the request is
https://run.plnkr.co/nPEfSPa0Ejn8MXjk/data%2Ffolder/test.json

So, in my real web application this is also happening, but the request is not being processed.
I thought that by using stripTrailingSlashes to false this could be avoided.

My code is here (also in the plunkr link)

angular

.module('appModule', ['ngResource'])
.controller('AppController', ['$resource', function($resource) {
  
  var vm = this;
  
  var reader = $resource(':context' + '/:file.json', {}, {
		query: {method: 'GET', params: {context: '@context', file: '@file'}}
	}, { stripTrailingSlashes: false });
	
	function load(context, file) {
	  console.log('resource in ' + context + '/' + file);
	  reader.query({context:context, file:file}, 
				function(data) {
				  console.log('success');
				  vm.data = data.name;
				}, 
				function(error) { 
				  console.log('error');
				}
			);
	}
	
	load('data/folder', 'test');
}])

Any help on that?

@gkalpak
Copy link
Member

gkalpak commented Nov 17, 2016

stripTrailingSlashes is totally irrelevant (it is about stripping trailing slashes). Your issue is with encoding slashes in parameter values.

I am not too keen on changing this (mainly due to its security implications). There is some discussion #7940.

In any case, this is a duplicate of #1388. Follow that threads for updates (but don't hold your breath 😃).

@gkalpak gkalpak closed this as completed Nov 17, 2016
@bieniekmateusz
Copy link

From the #7940 the relevant part here mentioned by @gkalpak is this:
$resource('project/:id', {"id": '@id'}, {query: {method: 'GET', isArray: true},}, {encodeSlashes: false})

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants