Skip to content

Commit 756b239

Browse files
committed
more tests
1 parent 86e50b9 commit 756b239

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export const parseDatabaseURL = function(
171171
secure = scheme === 'https' || scheme === 'wss';
172172
port = parseInt(host.substring(colonInd + 1), 10);
173173
} else {
174-
colonInd = dataURL.length;
174+
colonInd = host.length;
175175
}
176176

177177
const hostWithoutPort = host.slice(0, colonInd);
@@ -181,8 +181,8 @@ export const parseDatabaseURL = function(
181181
domain = hostWithoutPort; // Domain is at least 2 parts.
182182
} else {
183183
const dotInd = host.indexOf('.');
184-
domain = host.substring(dotInd + 1);
185184
subdomain = host.substring(0, dotInd).toLowerCase();
185+
domain = host.substring(dotInd + 1);
186186
// Normalize namespaces to lowercase to share storage / connection.
187187
namespace = subdomain;
188188
}

packages/database/test/database.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,27 @@ describe('Database Tests', () => {
7171
);
7272
});
7373

74+
it('Can get database with upper case URL', () => {
75+
const db = defaultApp.database('http://fOO.EUW1.firebaseDATABASE.app');
76+
expect(db).to.be.ok;
77+
expect(db.repo_.repoInfo_.namespace).to.equal('foo');
78+
expect(db.ref().toString()).to.equal(
79+
'https://foo.euw1.firebasedatabase.app/'
80+
);
81+
});
82+
7483
it('Can get database with localhost URL and port', () => {
7584
const db = defaultApp.database('http://localhost:80');
7685
expect(db).to.be.ok;
7786
expect(db.ref().toString()).to.equal('http://localhost:80/');
7887
});
7988

89+
it('Can get database with a upper case localhost URL', () => {
90+
const db = defaultApp.database('http://LOCALHOST');
91+
expect(db).to.be.ok;
92+
expect(db.ref().toString()).to.equal('https://localhost/');
93+
});
94+
8095
it('Can get database with localhost URL', () => {
8196
const db = defaultApp.database('http://localhost');
8297
expect(db).to.be.ok;
@@ -120,10 +135,19 @@ describe('Database Tests', () => {
120135
}).to.throw(/Database initialized multiple times/i);
121136
});
122137

138+
it('Databases with legacy domain', () => {
139+
expect(() => {
140+
defaultApp.database('http://foo.firebase.com/');
141+
}).to.throw(/is no longer supported/i);
142+
});
143+
123144
it('Databases with invalid custom URLs', () => {
124145
expect(() => {
125146
defaultApp.database('not-a-url');
126147
}).to.throw(/Cannot parse Firebase url/i);
148+
expect(() => {
149+
defaultApp.database('http://foo.com');
150+
}).to.throw(/Cannot parse Firebase url/i);
127151
expect(() => {
128152
defaultApp.database('http://fblocal.com');
129153
}).to.throw(/Cannot parse Firebase url/i);

0 commit comments

Comments
 (0)