Skip to content

Commit

Permalink
storage: encode file names
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed Nov 7, 2014
1 parent 247cbbf commit 3877b50
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/storage/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ File.prototype.copy = function(destination, callback) {
throw noDestinationError;
}
var path = util.format('/o/{srcName}/copyTo/b/{destBucket}/o/{destName}', {
srcName: this.name,
srcName: encodeURIComponent(this.name),
destBucket: destBucket.name,
destName: destName
destName: encodeURIComponent(destName)
});
this.makeReq_('POST', path, null, {}, function(err) {
if (err) {
Expand Down Expand Up @@ -272,7 +272,7 @@ File.prototype.createWriteStream = function(metadata) {
metadata: metadata,
request: {
qs: {
name: that.name,
name: that.name
},
uri: util.format('{base}/{bucket}/o', {
base: STORAGE_UPLOAD_BASE_URL,
Expand Down Expand Up @@ -300,7 +300,8 @@ File.prototype.createWriteStream = function(metadata) {
*/
File.prototype.delete = function(callback) {
callback = callback || util.noop;
this.makeReq_('DELETE', '/o/' + this.name, null, true, function(err) {
var path = '/o/' + encodeURIComponent(this.name);
this.makeReq_('DELETE', path, null, true, function(err) {
if (err) {
callback(err);
return;
Expand All @@ -319,7 +320,8 @@ File.prototype.delete = function(callback) {
*/
File.prototype.getMetadata = function(callback) {
callback = callback || util.noop;
this.makeReq_('GET', '/o/' + this.name, null, true, function(err, resp) {
var path = '/o/' + encodeURIComponent(this.name);
this.makeReq_('GET', path, null, true, function(err, resp) {
if (err) {
callback(err);
return;
Expand Down Expand Up @@ -365,7 +367,9 @@ File.prototype.getSignedUrl = function(options, callback) {
delete: 'DELETE'
}[options.action];

options.resource = '/' + this.bucket.name + '/' + this.name;
var name = encodeURIComponent(this.name);

options.resource = '/' + this.bucket.name + '/' + name;

var makeAuthorizedRequest_ = this.bucket.storage.makeAuthorizedRequest_;

Expand Down Expand Up @@ -411,8 +415,8 @@ File.prototype.getSignedUrl = function(options, callback) {
*/
File.prototype.setMetadata = function(metadata, callback) {
callback = callback || util.noop;
this.makeReq_(
'PATCH', '/o/' + this.name, null, metadata, function(err, resp) {
var path = '/o/' + encodeURIComponent(this.name);
this.makeReq_('PATCH', path, null, metadata, function(err, resp) {
if (err) {
callback(err);
return;
Expand Down

0 comments on commit 3877b50

Please sign in to comment.