Permalink
Browse files

GH-9 Encode URIs so that spaces, etc. are allowed in the client

  • Loading branch information...
1 parent 23bbe7e commit 120f3f5b039f30d8cee21081dbbcb86f715ed079 Mark Cavage committed Nov 9, 2011
Showing with 38 additions and 1 deletion.
  1. +38 −1 lib/cloudapi.js
View
@@ -2,6 +2,7 @@
var assert = require('assert');
var crypto = require('crypto');
+var qs = require('querystring');
var createCache = require('lru-cache');
var restify = require('restify');
@@ -63,6 +64,42 @@ function _clone(object) {
}
+function _encodeURI(path) {
+ assert.ok(path);
+
+ var ret = '';
+ var str = '';
+ var esc = false;
+
+ function append() {
+ if (str.length)
+ ret += '/' + qs.escape(str);
+ str = '';
+ return ret;
+ }
+
+ for (var i = 0; i < path.length; i++) {
+ if (!esc) {
+ switch (path[i]) {
+ case '\\':
+ esc = true;
+ break;
+ case '/':
+ append();
+ break;
+ default:
+ str += path[i];
+ break;
+ }
+ } else {
+ str += path[i];
+ esc = false;
+ }
+ }
+
+ return append();
+};
+
///--- Exported CloudAPI Client
/**
@@ -2006,7 +2043,7 @@ CloudAPI.prototype._request = function(path, body, callback) {
var now = restify.httpDate();
var obj = {
- path: path,
+ path: _encodeURI(path),
headers: {
Authorization: authz,
Date: now

0 comments on commit 120f3f5

Please sign in to comment.