Skip to content

Commit b6e0ffd

Browse files
committed
Fix bug and tests
1 parent f499be2 commit b6e0ffd

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

packages/storage/src/implementation/url.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@
2121
import { UrlParams } from './requestinfo';
2222

2323
export function makeUrl(urlPart: string, host: string): string {
24-
return `https://${host}/v0${urlPart}`;
24+
const protocolMatch = host.match(/^(\w+):\/\/.+/);
25+
const protocol = protocolMatch?.[1];
26+
let origin = host;
27+
if (protocol == null) {
28+
origin = `https://${host}`;
29+
}
30+
return `${origin}/v0${urlPart}`;
2531
}
2632

2733
export function makeQueryString(params: UrlParams): string {

packages/storage/test/unit/service.compat.test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ describe('Firebase Storage > Service', () => {
172172
});
173173
});
174174
describe('useStorageEmulator(service, host, port)', () => {
175-
it('sets emulator host correctly', () => {
175+
it('sets emulator host correctly', done => {
176176
function newSend(
177177
xhrio: TestingXhrIo,
178178
url: string,
@@ -182,8 +182,9 @@ describe('Firebase Storage > Service', () => {
182182
): void {
183183
// Expect emulator host to be in url of storage operations requests,
184184
// in this case getDownloadURL.
185-
expect(url).to.include('http://test.host.org:1234');
185+
expect(url).to.match(/^http:\/\/test\.host\.org:1234.+/);
186186
xhrio.abort();
187+
done();
187188
}
188189
const service = makeService(
189190
testShared.fakeApp,

packages/storage/test/unit/service.exp.test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ GOOG4-RSA-SHA256`
221221
});
222222
});
223223
describe('useStorageEmulator(service, host, port)', () => {
224-
it('sets emulator host correctly', () => {
224+
it('sets emulator host correctly', done => {
225225
function newSend(
226226
xhrio: TestingXhrIo,
227227
url: string,
@@ -231,8 +231,9 @@ GOOG4-RSA-SHA256`
231231
): void {
232232
// Expect emulator host to be in url of storage operations requests,
233233
// in this case getDownloadURL.
234-
expect(url).to.include('http://test.host.org:1234');
234+
expect(url).to.match(/^http:\/\/test\.host\.org:1234.+/);
235235
xhrio.abort();
236+
done();
236237
}
237238
const service = new StorageService(
238239
testShared.fakeApp,

0 commit comments

Comments
 (0)