Skip to content

Commit 1494388

Browse files
committed
generalize
1 parent e223614 commit 1494388

File tree

1 file changed

+11
-14
lines changed
  • packages/database/src/core/util/libs

1 file changed

+11
-14
lines changed

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

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const parseRepoInfo = function(
7272
const parsedUrl = parseDatabaseURL(dataURL),
7373
namespace = parsedUrl.namespace;
7474

75-
if (parsedUrl.domain === 'firebase') {
75+
if (parsedUrl.domain === 'firebase.com') {
7676
fatal(
7777
parsedUrl.host +
7878
' is no longer supported. ' +
@@ -174,21 +174,18 @@ export const parseDatabaseURL = function(
174174
colonInd = dataURL.length;
175175
}
176176

177-
const parts = host.split('.');
178-
if (parts.length === 4) {
179-
domain = parts[1] + "." + parts[2];
180-
subdomain = parts[0].toLowerCase();
181-
namespace = subdomain;
182-
} else if (parts.length === 3) {
177+
let dotInd = host.indexOf('.');
178+
if (dotInd === -1) {
179+
dotInd = colonInd;
180+
}
181+
const hostFirstPart = host.substring(0, dotInd);
182+
if (hostFirstPart.toLowerCase() === 'localhost') {
183+
domain = 'localhost';
184+
} else {
185+
domain = host.substring(dotInd+1);
183186
// Normalize namespaces to lowercase to share storage / connection.
184-
domain = parts[1];
185-
subdomain = parts[0].toLowerCase();
186-
// We interpret the subdomain of a 3 component URL as the namespace name.
187+
subdomain = hostFirstPart.toLowerCase();
187188
namespace = subdomain;
188-
} else if (parts.length === 2) {
189-
domain = parts[0];
190-
} else if (parts[0].slice(0, colonInd).toLowerCase() === 'localhost') {
191-
domain = 'localhost';
192189
}
193190
// Always treat the value of the `ns` as the namespace name if it is present.
194191
if ('ns' in queryParams) {

0 commit comments

Comments
 (0)