Skip to content

Commit 3877b50

Browse files
storage: encode file names
1 parent 247cbbf commit 3877b50

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

lib/storage/file.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ File.prototype.copy = function(destination, callback) {
159159
throw noDestinationError;
160160
}
161161
var path = util.format('/o/{srcName}/copyTo/b/{destBucket}/o/{destName}', {
162-
srcName: this.name,
162+
srcName: encodeURIComponent(this.name),
163163
destBucket: destBucket.name,
164-
destName: destName
164+
destName: encodeURIComponent(destName)
165165
});
166166
this.makeReq_('POST', path, null, {}, function(err) {
167167
if (err) {
@@ -272,7 +272,7 @@ File.prototype.createWriteStream = function(metadata) {
272272
metadata: metadata,
273273
request: {
274274
qs: {
275-
name: that.name,
275+
name: that.name
276276
},
277277
uri: util.format('{base}/{bucket}/o', {
278278
base: STORAGE_UPLOAD_BASE_URL,
@@ -300,7 +300,8 @@ File.prototype.createWriteStream = function(metadata) {
300300
*/
301301
File.prototype.delete = function(callback) {
302302
callback = callback || util.noop;
303-
this.makeReq_('DELETE', '/o/' + this.name, null, true, function(err) {
303+
var path = '/o/' + encodeURIComponent(this.name);
304+
this.makeReq_('DELETE', path, null, true, function(err) {
304305
if (err) {
305306
callback(err);
306307
return;
@@ -319,7 +320,8 @@ File.prototype.delete = function(callback) {
319320
*/
320321
File.prototype.getMetadata = function(callback) {
321322
callback = callback || util.noop;
322-
this.makeReq_('GET', '/o/' + this.name, null, true, function(err, resp) {
323+
var path = '/o/' + encodeURIComponent(this.name);
324+
this.makeReq_('GET', path, null, true, function(err, resp) {
323325
if (err) {
324326
callback(err);
325327
return;
@@ -365,7 +367,9 @@ File.prototype.getSignedUrl = function(options, callback) {
365367
delete: 'DELETE'
366368
}[options.action];
367369

368-
options.resource = '/' + this.bucket.name + '/' + this.name;
370+
var name = encodeURIComponent(this.name);
371+
372+
options.resource = '/' + this.bucket.name + '/' + name;
369373

370374
var makeAuthorizedRequest_ = this.bucket.storage.makeAuthorizedRequest_;
371375

@@ -411,8 +415,8 @@ File.prototype.getSignedUrl = function(options, callback) {
411415
*/
412416
File.prototype.setMetadata = function(metadata, callback) {
413417
callback = callback || util.noop;
414-
this.makeReq_(
415-
'PATCH', '/o/' + this.name, null, metadata, function(err, resp) {
418+
var path = '/o/' + encodeURIComponent(this.name);
419+
this.makeReq_('PATCH', path, null, metadata, function(err, resp) {
416420
if (err) {
417421
callback(err);
418422
return;

0 commit comments

Comments
 (0)