Skip to content

Commit d4240fa

Browse files
authored
fix: use correct indices for file.from and fix tests to verify names (#2449)
1 parent 2eacda8 commit d4240fa

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/file.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,11 +2410,11 @@ class File extends ServiceObject<File, FileMetadata> {
24102410
const httpsMatches = [...publicUrlOrGsUrl.matchAll(HTTPS_PUBLIC_URL_REGEX)];
24112411

24122412
if (gsMatches.length > 0) {
2413-
const bucket = new Bucket(storageInstance, gsMatches[0][1]);
2414-
return new File(bucket, gsMatches[0][2], options);
2413+
const bucket = new Bucket(storageInstance, gsMatches[0][2]);
2414+
return new File(bucket, gsMatches[0][3], options);
24152415
} else if (httpsMatches.length > 0) {
2416-
const bucket = new Bucket(storageInstance, httpsMatches[0][2]);
2417-
return new File(bucket, httpsMatches[0][3], options);
2416+
const bucket = new Bucket(storageInstance, httpsMatches[0][3]);
2417+
return new File(bucket, httpsMatches[0][4], options);
24182418
} else {
24192419
throw new Error(
24202420
'URL string must be of format gs://bucket/file or https://storage.googleapis.com/bucket/file'

test/file.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5180,26 +5180,26 @@ describe('File', () => {
51805180
const result = File.from(gsUrl, STORAGE);
51815181

51825182
assert(result);
5183-
assert(result.bucket.name, 'mybucket');
5184-
assert(result.name, 'myfile');
5183+
assert.strictEqual(result.bucket.name, 'mybucket');
5184+
assert.strictEqual(result.name, 'myfile');
51855185
});
51865186

51875187
it('should create a File object from a gs:// formatted URL including a folder', () => {
51885188
const gsUrl = 'gs://mybucket/myfolder/myfile';
51895189
const result = File.from(gsUrl, STORAGE);
51905190

51915191
assert(result);
5192-
assert(result.bucket.name, 'mybucket');
5193-
assert(result.name, 'myfolder/myfile');
5192+
assert.strictEqual(result.bucket.name, 'mybucket');
5193+
assert.strictEqual(result.name, 'myfolder/myfile');
51945194
});
51955195

51965196
it('should create a File object from a https:// formatted URL', () => {
51975197
const httpsUrl = 'https://storage.googleapis.com/mybucket/myfile';
51985198
const result = File.from(httpsUrl, STORAGE);
51995199

52005200
assert(result);
5201-
assert(result.bucket.name, 'mybucket');
5202-
assert(result.name, 'myfile');
5201+
assert.strictEqual(result.bucket.name, 'mybucket');
5202+
assert.strictEqual(result.name, 'myfile');
52035203
});
52045204

52055205
it('should create a File object from a https:// formatted URL including a folder', () => {
@@ -5208,8 +5208,8 @@ describe('File', () => {
52085208
const result = File.from(httpsUrl, STORAGE);
52095209

52105210
assert(result);
5211-
assert(result.bucket.name, 'mybucket');
5212-
assert(result.name, 'myfolder/myfile');
5211+
assert.strictEqual(result.bucket.name, 'mybucket');
5212+
assert.strictEqual(result.name, 'myfolder/myfile');
52135213
});
52145214

52155215
it('should throw an error when invoked with an incorrectly formatted URL', () => {

0 commit comments

Comments
 (0)