Skip to content

Commit b4fbdaa

Browse files
committed
Use encodeURIComponent to prevent requests to type(s) with special chars (områder) from failing
1 parent 74a7f86 commit b4fbdaa

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

index.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,28 @@ var request = module.exports._requestDefaults();
2828
'turer'
2929
].forEach(function(type) {
3030
module.exports[type] = function(params, callback) {
31-
if (!callback) { return request.get({url: type, qs: params}); }
32-
request.get({url: type, qs: params}, callback);
31+
if (!callback) { return request.get({url: encodeURIComponent(type), qs: params}); }
32+
request.get({url: encodeURIComponent(type), qs: params}, callback);
3333
};
3434

3535
module.exports[type].post = function(data, callback) {
36-
if (!callback) { return request.post({url: type, body: data}); }
37-
request.post({url: type, body: data}, callback);
36+
if (!callback) { return request.post({url: encodeURIComponent(type), body: data}); }
37+
request.post({url: encodeURIComponent(type), body: data}, callback);
3838
};
3939

4040
module.exports[type].get = function(id, callback) {
41-
if (!callback) { return request.get({url: type + '/' + id}); }
42-
request.get({url: type + '/' + id}, callback);
41+
if (!callback) { return request.get({url: encodeURIComponent(type) + '/' + id}); }
42+
request.get({url: encodeURIComponent(type) + '/' + id}, callback);
4343
};
4444

4545
module.exports[type].put = function(id, data, callback) {
46-
if (!callback) { return request.put({url: type + '/' + id, body: data}); }
47-
request.put({url: type + '/' + id, body: data}, callback);
46+
if (!callback) { return request.put({url: encodeURIComponent(type) + '/' + id, body: data}); }
47+
request.put({url: encodeURIComponent(type) + '/' + id, body: data}, callback);
4848
};
4949

5050
module.exports[type].patch = function(id, data, callback) {
51-
if (!callback) { return request.patch({url: type + '/' + id, body: data}); }
52-
request.patch({url: type + '/' + id, body: data}, callback);
51+
if (!callback) { return request.patch({url: encodeURIComponent(type) + '/' + id, body: data}); }
52+
request.patch({url: encodeURIComponent(type) + '/' + id, body: data}, callback);
5353
};
5454
});
5555

0 commit comments

Comments
 (0)