Skip to content

Commit 3ccba53

Browse files
committed
Strip query params from the host
1 parent 8bffaa6 commit 3ccba53

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

packages/database/src/core/util/libs/parser.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,17 @@ export const parseURL = function(
147147
domain = 'localhost';
148148
}
149149
// Support `ns` query param if subdomain not already set
150-
if (subdomain === '') {
151-
const queryStartIndex = host.indexOf('?');
152-
if (queryStartIndex != -1) {
150+
const queryStartIndex = host.indexOf('?');
151+
if (queryStartIndex > 0) {
152+
if (subdomain === '') {
153153
const queryString = host.substring(queryStartIndex, host.length);
154154
const match = queryString.match(/ns=([a-zA-Z0-9-]+)/);
155155
if (match.length > 0) {
156156
subdomain = match[1];
157-
host = host.substring(0, queryStartIndex);
158157
}
159158
}
159+
// Always remove all query params from the host
160+
host = host.substring(0, queryStartIndex);
160161
}
161162
}
162163

packages/database/test/database.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe('Database Tests', function() {
8787
var db = defaultApp.database('http://bar.firebaseio.com?ns=foo');
8888
expect(db).to.be.ok;
8989
expect(db.repo_.repoInfo_.namespace).to.equal('bar');
90-
expect(db.ref().toString()).to.equal('https://bar.firebaseio.com?ns=foo/');
90+
expect(db.ref().toString()).to.equal('https://bar.firebaseio.com/');
9191
});
9292

9393
it('Different instances for different URLs', function() {

0 commit comments

Comments
 (0)