Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit d76b9e7

Browse files
fix: remove trailing slashes from bucket name. (#266)
Fixes #170 This cleans up the fragments of a gs:// URL, should the user provide one to the Bucket constructor.
1 parent 29cb313 commit d76b9e7

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/bucket.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ class Bucket extends ServiceObject {
302302
constructor(storage, name, options?) {
303303
options = options || {};
304304

305-
name = name.replace(/^gs:\/\//, '');
305+
// Allow for "gs://"-style input, and strip any trailing slashes.
306+
name = name.replace(/^gs:\/\//, '').replace(/\/+$/, '');
306307

307308
const methods = {
308309
/**

test/bucket.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ describe('Bucket', () => {
177177
assert.strictEqual(bucket.name, 'bucket-name');
178178
});
179179

180+
it('should remove a trailing /', () => {
181+
const bucket = new Bucket(STORAGE, 'bucket-name/');
182+
assert.strictEqual(bucket.name, 'bucket-name');
183+
});
184+
180185
it('should localize the name', () => {
181186
assert.strictEqual(bucket.name, BUCKET_NAME);
182187
});

0 commit comments

Comments
 (0)