Skip to content

Commit 0240e17

Browse files
committed
more
1 parent 756b239 commit 0240e17

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,9 @@ export const parseDatabaseURL = function(
178178
if (hostWithoutPort.toLowerCase() === 'localhost') {
179179
domain = 'localhost';
180180
} else if (hostWithoutPort.split('.').length <= 2) {
181-
domain = hostWithoutPort; // Domain is at least 2 parts.
181+
domain = hostWithoutPort;
182182
} else {
183+
// Interpret the subdomain of a 3 or more component URL as the namespace name.
183184
const dotInd = host.indexOf('.');
184185
subdomain = host.substring(0, dotInd).toLowerCase();
185186
domain = host.substring(dotInd + 1);

packages/database/test/database.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ describe('Database Tests', () => {
8080
);
8181
});
8282

83+
it('Can get database with localhost URL', () => {
84+
const db = defaultApp.database('http://localhost');
85+
expect(db).to.be.ok;
86+
expect(db.ref().toString()).to.equal('https://localhost/');
87+
});
88+
8389
it('Can get database with localhost URL and port', () => {
8490
const db = defaultApp.database('http://localhost:80');
8591
expect(db).to.be.ok;
@@ -92,9 +98,10 @@ describe('Database Tests', () => {
9298
expect(db.ref().toString()).to.equal('https://localhost/');
9399
});
94100

95-
it('Can get database with localhost URL', () => {
96-
const db = defaultApp.database('http://localhost');
101+
it('Can get database with a upper case localhost URL and ns', () => {
102+
const db = defaultApp.database('http://LOCALHOST?ns=foo');
97103
expect(db).to.be.ok;
104+
expect(db.repo_.repoInfo_.namespace).to.equal('foo');
98105
expect(db.ref().toString()).to.equal('https://localhost/');
99106
});
100107

0 commit comments

Comments
 (0)