From 39ab1ae03dd5666c6ca7e4c6c1a1f362636bbccb Mon Sep 17 00:00:00 2001 From: Denis DelGrosso Date: Mon, 28 Mar 2022 15:01:21 +0000 Subject: [PATCH 1/2] fix: encode name portion when calling publicUrl function --- src/file.ts | 2 +- test/file.ts | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/file.ts b/src/file.ts index c49484d8f..f92176251 100644 --- a/src/file.ts +++ b/src/file.ts @@ -3320,7 +3320,7 @@ class File extends ServiceObject { * ``` */ publicUrl(): string { - return `${this.storage.apiEndpoint}/${this.bucket.name}/${this.name}`; + return `${this.storage.apiEndpoint}/${this.bucket.name}/${encodeURIComponent(this.name)}`; } move( diff --git a/test/file.ts b/test/file.ts index ece8784df..7f43a8704 100644 --- a/test/file.ts +++ b/test/file.ts @@ -3937,7 +3937,7 @@ describe('File', () => { const file = new File(BUCKET, NAME); assert.strictEqual( file.publicUrl(), - `https://storage.googleapis.com/bucket-name/${NAME}` + `https://storage.googleapis.com/bucket-name/${encodeURIComponent(NAME)}` ); done(); }); @@ -3947,7 +3947,7 @@ describe('File', () => { const file = new File(BUCKET, NAME); assert.strictEqual( file.publicUrl(), - `https://storage.googleapis.com/bucket-name/${NAME}` + `https://storage.googleapis.com/bucket-name/${encodeURIComponent(NAME)}` ); done(); }); @@ -3957,7 +3957,7 @@ describe('File', () => { const file = new File(BUCKET, NAME); assert.strictEqual( file.publicUrl(), - `https://storage.googleapis.com/bucket-name/${NAME}` + `https://storage.googleapis.com/bucket-name/${encodeURIComponent(NAME)}` ); done(); }); @@ -3967,7 +3967,17 @@ describe('File', () => { const file = new File(BUCKET, NAME); assert.strictEqual( file.publicUrl(), - `https://storage.googleapis.com/bucket-name/${NAME}` + `https://storage.googleapis.com/bucket-name/${encodeURIComponent(NAME)}` + ); + done(); + }); + + it('with an ampersand in the name', done => { + const NAME = '&foo'; + const file = new File(BUCKET, NAME); + assert.strictEqual( + file.publicUrl(), + `https://storage.googleapis.com/bucket-name/${encodeURIComponent(NAME)}` ); done(); }); From e1741a426289428a393f1fdee2fa67e5f64408ee Mon Sep 17 00:00:00 2001 From: Denis DelGrosso Date: Mon, 28 Mar 2022 15:05:59 +0000 Subject: [PATCH 2/2] linter fixes --- src/file.ts | 4 +++- test/file.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/file.ts b/src/file.ts index f92176251..064847c92 100644 --- a/src/file.ts +++ b/src/file.ts @@ -3320,7 +3320,9 @@ class File extends ServiceObject { * ``` */ publicUrl(): string { - return `${this.storage.apiEndpoint}/${this.bucket.name}/${encodeURIComponent(this.name)}`; + return `${this.storage.apiEndpoint}/${ + this.bucket.name + }/${encodeURIComponent(this.name)}`; } move( diff --git a/test/file.ts b/test/file.ts index 7f43a8704..2cdd6f7ac 100644 --- a/test/file.ts +++ b/test/file.ts @@ -3974,7 +3974,7 @@ describe('File', () => { it('with an ampersand in the name', done => { const NAME = '&foo'; - const file = new File(BUCKET, NAME); + const file = new File(BUCKET, NAME); assert.strictEqual( file.publicUrl(), `https://storage.googleapis.com/bucket-name/${encodeURIComponent(NAME)}`