Skip to content

Commit f7d65ba

Browse files
committed
Fixed non-http protocols
1 parent a89fc04 commit f7d65ba

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/data-connect/src/api/DataConnect.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,14 @@ const FIREBASE_DATA_CONNECT_EMULATOR_HOST_VAR =
7272
*/
7373
export function parseOptions(fullHost: string): TransportOptions {
7474
const trimmedHost = fullHost.trim();
75-
if (trimmedHost.startsWith('http://') || trimmedHost.startsWith('https://')) {
75+
if (fullHost.includes('://')) {
7676
const [protocol, host] = trimmedHost.split('://');
77+
if (protocol !== 'http' && protocol !== 'https') {
78+
throw new DataConnectError(
79+
Code.INVALID_ARGUMENT,
80+
`Protocol ${protocol} is not supported. Use 'http' or 'https' instead.`
81+
);
82+
}
7783
const isSecure = protocol === 'https';
7884
return { host, sslEnabled: isSecure };
7985
}

packages/data-connect/test/unit/dataconnect.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,10 @@ describe('Data Connect Test', () => {
8181
expect(parsedHost.host).to.eq(host);
8282
expect(parsedHost.sslEnabled).to.be.false;
8383
});
84+
it('should throw for non-http protocols', async () => {
85+
const host = 'ftp://localhost';
86+
expect(() => parseOptions(host)).to.throw(
87+
"Protocol ftp is not supported. Use 'http' or 'https' instead."
88+
);
89+
});
8490
});

0 commit comments

Comments
 (0)