Skip to content

Commit

Permalink
storage: strip leading slash in File() constructor (#2269)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjihrig authored and stephenplusplus committed May 1, 2017
1 parent a0341b2 commit e107247
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/storage/src/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function File(bucket, name, options) {

Object.defineProperty(this, 'name', {
enumerable: true,
value: name
value: name.replace(/^\/+/, '') // Remove leading slashes.
});

var generation = parseInt(options.generation, 10);
Expand Down
5 changes: 5 additions & 0 deletions packages/storage/test/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ describe('File', function() {
assert.strictEqual(file.storage, BUCKET.storage);
});

it('should strip a single leading slash', function() {
var file = new File(BUCKET, '/name');
assert.strictEqual(file.name, 'name');
});

it('should accept specifying a generation', function() {
var file = new File(BUCKET, 'name', { generation: 2 });
assert.equal(file.generation, 2);
Expand Down

0 comments on commit e107247

Please sign in to comment.