Skip to content

Commit

Permalink
[minor] encode all usernames passed as parameters to ensure paths are…
Browse files Browse the repository at this point in the history
… hit
  • Loading branch information
Swaagie committed Dec 16, 2014
1 parent ead0582 commit 8fb4ad5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
37 changes: 30 additions & 7 deletions node.js/lib/client/users.js
Expand Up @@ -42,7 +42,11 @@ Users.prototype.auth = function (callback) {
// Creates a new user with the properties specified by `user`.
//
Users.prototype.create = function (user, callback) {
this.request({ method: 'POST', uri: ['users', user.username], body: user }, callback);
this.request({
method: 'POST',
uri: ['users', encodeURIComponent(user.username)],
body: user
}, callback);
};

//
Expand All @@ -52,7 +56,9 @@ Users.prototype.create = function (user, callback) {
// Checks the availability of the specified `username`.
//
Users.prototype.available = function (username, callback) {
this.request({ uri: ['users', encodeURIComponent(username), 'available'] }, callback);
this.request({
uri: ['users', encodeURIComponent(username), 'available']
}, callback);
};

//
Expand All @@ -73,7 +79,9 @@ Users.prototype.emailTaken = function (email, callback) {
// Retrieves data for the specified user.
//
Users.prototype.view = function (username, callback) {
this.request({ uri: ['users', username] }, callback);
this.request({
uri: ['users', encodeURIComponent(username)]
}, callback);
};

//
Expand All @@ -83,7 +91,11 @@ Users.prototype.view = function (username, callback) {
// Confirms the specified `user` by sending the invite code in the `user` specified.
//
Users.prototype.confirm = function (user, callback) {
this.request({ method: 'POST', uri: ['users', user.username, 'confirm'], body: user }, callback);
this.request({
method: 'POST',
uri: ['users', encodeURIComponent(user.username), 'confirm'],
body: user
}, callback);
};

//
Expand All @@ -99,7 +111,11 @@ Users.prototype.forgot = function (username, params, callback) {
params = {};
}

this.request({ method: 'POST', uri: ['users', username, 'forgot'], body: params }, callback);
this.request({
method: 'POST',
uri: ['users', encodeURIComponent(username), 'forgot'],
body: params
}, callback);
};

//
Expand All @@ -110,7 +126,11 @@ Users.prototype.forgot = function (username, params, callback) {
// Update user account information.
//
Users.prototype.update = function (username, object, callback) {
this.request({ method: 'PUT', uri: ['users', username], body: object }, callback);
this.request({
method: 'PUT',
uri: ['users', encodeURIComponent(username)],
body: object
}, callback);
};

//
Expand All @@ -122,5 +142,8 @@ Users.prototype.update = function (username, object, callback) {
// So sad to see you go.
//
Users.prototype.destroy = function (username, callback) {
this.request({ method: 'DELETE', uri: ['users', username] }, callback);
this.request({
method: 'DELETE',
uri: ['users', encodeURIComponent(username)]
}, callback);
};
2 changes: 1 addition & 1 deletion node.js/package.json
@@ -1,6 +1,6 @@
{
"name": "nodejitsu-api",
"version": "0.6.5",
"version": "0.6.6",
"description": "nodejitsu API client wrapper",
"keywords": ["nodejitsu", "nodejitsu-api"],
"homepage": "http://github.com/nodejitsu/nodejitsu-api",
Expand Down

0 comments on commit 8fb4ad5

Please sign in to comment.