Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions packages/database/src/core/util/libs/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,14 @@ export const parseURL = function(
host = dataURL.substring(0, slashInd);
pathString = decodePath(dataURL.substring(slashInd));

// If we have a port, use scheme for determining if it's secure.
colonInd = host.indexOf(':');
if (colonInd >= 0) {
secure = scheme === 'https' || scheme === 'wss';
port = parseInt(host.substring(colonInd + 1), 10);
} else {
colonInd = dataURL.length;
}

const parts = host.split('.');
if (parts.length === 3) {
Expand All @@ -139,12 +146,6 @@ export const parseURL = function(
} else if (parts[0].slice(0, colonInd).toLowerCase() === 'localhost') {
domain = 'localhost';
}

// If we have a port, use scheme for determining if it's secure.
if (colonInd >= 0) {
secure = scheme === 'https' || scheme === 'wss';
port = parseInt(host.substring(colonInd + 1), 10);
}
}

return {
Expand Down
8 changes: 7 additions & 1 deletion packages/database/test/database.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,18 @@ describe('Database Tests', function() {
expect(db.ref().toString()).to.equal('https://foo.bar.com/');
});

it('Can get database with localhost URL', function() {
it('Can get database with localhost URL and port', function() {
var db = defaultApp.database('http://localhost:80');
expect(db).to.be.ok;
expect(db.ref().toString()).to.equal('http://localhost:80/');
});

it('Can get database with localhost URL', function() {
var db = defaultApp.database('http://localhost');
expect(db).to.be.ok;
expect(db.ref().toString()).to.equal('https://localhost/');
});

it('Different instances for different URLs', function() {
var db1 = defaultApp.database('http://foo1.bar.com');
var db2 = defaultApp.database('http://foo2.bar.com');
Expand Down