Skip to content

Commit 3f07169

Browse files
Modify to actually support GCS format
1 parent ec63394 commit 3f07169

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

packages/storage/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@firebase/storage",
3-
"version": "0.3.29",
3+
"version": "0.3.30",
44
"description": "",
55
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
66
"main": "dist/index.cjs.js",
@@ -22,8 +22,8 @@
2222
"license": "Apache-2.0",
2323
"dependencies": {
2424
"@firebase/storage-types": "0.3.11",
25-
"@firebase/util": "0.2.42",
26-
"@firebase/component": "0.1.7",
25+
"@firebase/util": "0.2.43",
26+
"@firebase/component": "0.1.8",
2727
"tslib": "1.11.1"
2828
},
2929
"peerDependencies": {

packages/storage/src/implementation/location.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* object location.
2121
*/
2222
import * as errorsExports from './error';
23+
import { DEFAULT_HOST } from './constants';
2324

2425
/**
2526
* @struct
@@ -75,23 +76,41 @@ export class Location {
7576
}
7677
}
7778
const gsPath = '(/(.*))?$';
78-
const path = '(/([^?#]*).*)?$';
7979
const gsRegex = new RegExp('^gs://' + bucketDomain + gsPath, 'i');
8080
const gsIndices = { bucket: 1, path: 3 };
8181

8282
function httpModify(loc: Location): void {
8383
loc.path_ = decodeURIComponent(loc.path);
8484
}
8585
const version = 'v[A-Za-z0-9_]+';
86-
const hostRegex = "(?:firebase)?storage.googleapis.com";
87-
const httpRegex = new RegExp(
88-
`^https?://${hostRegex}/${version}/b/${bucketDomain}/o${path}`,
86+
const firebaseStorageHost = DEFAULT_HOST.replace(/[.]/g, '\\.');
87+
const firebaseStoragePath = '(/([^?#]*).*)?$';
88+
const firebaseStorageRegExp = new RegExp(
89+
`^https?://${firebaseStorageHost}/${version}/b/${bucketDomain}/o${firebaseStoragePath}`,
8990
'i'
9091
);
91-
const httpIndices = { bucket: 1, path: 3 };
92+
const firebaseStorageIndices = { bucket: 1, path: 3 };
93+
94+
const cloudStorageHost = 'storage.googleapis.com';
95+
const cloudStoragePath = '([^?]*)';
96+
const cloudStorageRegExp = new RegExp(
97+
`^https?://${cloudStorageHost}/${bucketDomain}/${cloudStoragePath}`,
98+
'i'
99+
);
100+
const cloudStorageIndices = { bucket: 1, path: 2 };
101+
92102
const groups = [
93103
{ regex: gsRegex, indices: gsIndices, postModify: gsModify },
94-
{ regex: httpRegex, indices: httpIndices, postModify: httpModify }
104+
{
105+
regex: firebaseStorageRegExp,
106+
indices: firebaseStorageIndices,
107+
postModify: httpModify
108+
},
109+
{
110+
regex: cloudStorageRegExp,
111+
indices: cloudStorageIndices,
112+
postModify: httpModify
113+
}
95114
];
96115
for (let i = 0; i < groups.length; i++) {
97116
const group = groups[i];

packages/storage/test/service.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,16 @@ describe('Firebase Storage > Service', () => {
184184
});
185185
it('Works with storage.googleapis.com URLs', () => {
186186
const ref = service.refFromURL(
187-
`http://storage.googleapis.com/v0/b/` +
188-
'mybucket/o/child%2Fpath%2Fimage.png?downloadToken=hello'
187+
`https://storage.googleapis.com/mybucket/path%20with%20space/image.png`
189188
);
190-
assert.equal(ref.toString(), 'gs://mybucket/child/path/image.png');
189+
assert.equal(ref.toString(), 'gs://mybucket/path with space/image.png');
190+
});
191+
it('Works with storage.googleapis.com URLs with query params', () => {
192+
const ref = service.refFromURL(
193+
`https://storage.googleapis.com/mybucket/path%20with%20space/image.png?X-Goog-Algorithm=
194+
GOOG4-RSA-SHA256`
195+
);
196+
assert.equal(ref.toString(), 'gs://mybucket/path with space/image.png');
191197
});
192198
});
193199
describe('Argument verification', () => {

0 commit comments

Comments
 (0)