File tree Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -57,7 +57,10 @@ export const parseRepoInfo = function(
5757 }
5858
5959 // Catch common error of uninitialized namespace value.
60- if ( ! namespace || namespace == 'undefined' ) {
60+ if (
61+ ( ! namespace || namespace == 'undefined' ) &&
62+ parsedUrl . domain !== 'localhost'
63+ ) {
6164 fatal (
6265 'Cannot parse Firebase url. Please use https://<YOUR FIREBASE>.firebaseio.com'
6366 ) ;
@@ -124,17 +127,20 @@ export const parseURL = function(
124127 host = dataURL . substring ( 0 , slashInd ) ;
125128 pathString = decodePath ( dataURL . substring ( slashInd ) ) ;
126129
130+ colonInd = host . indexOf ( ':' ) ;
131+
127132 const parts = host . split ( '.' ) ;
128133 if ( parts . length === 3 ) {
129134 // Normalize namespaces to lowercase to share storage / connection.
130135 domain = parts [ 1 ] ;
131136 subdomain = parts [ 0 ] . toLowerCase ( ) ;
132137 } else if ( parts . length === 2 ) {
133138 domain = parts [ 0 ] ;
139+ } else if ( parts [ 0 ] . slice ( 0 , colonInd ) . toLowerCase ( ) === 'localhost' ) {
140+ domain = 'localhost' ;
134141 }
135142
136143 // If we have a port, use scheme for determining if it's secure.
137- colonInd = host . indexOf ( ':' ) ;
138144 if ( colonInd >= 0 ) {
139145 secure = scheme === 'https' || scheme === 'wss' ;
140146 port = parseInt ( host . substring ( colonInd + 1 ) , 10 ) ;
Original file line number Diff line number Diff line change @@ -417,7 +417,8 @@ export const validateUrl = function(
417417 if (
418418 ! ( typeof parsedUrl . repoInfo . host === 'string' ) ||
419419 parsedUrl . repoInfo . host . length === 0 ||
420- ! isValidKey ( parsedUrl . repoInfo . namespace ) ||
420+ ( ! isValidKey ( parsedUrl . repoInfo . namespace ) &&
421+ parsedUrl . repoInfo . host . split ( ':' ) [ 0 ] !== 'localhost' ) ||
421422 ( pathString . length !== 0 && ! isValidRootPathString ( pathString ) )
422423 ) {
423424 throw new Error (
Original file line number Diff line number Diff line change @@ -64,6 +64,12 @@ describe('Database Tests', function() {
6464 expect ( db . ref ( ) . toString ( ) ) . to . equal ( 'https://foo.bar.com/' ) ;
6565 } ) ;
6666
67+ it ( 'Can get database with localhost URL' , function ( ) {
68+ var db = defaultApp . database ( 'http://localhost:80' ) ;
69+ expect ( db ) . to . be . ok ;
70+ expect ( db . ref ( ) . toString ( ) ) . to . equal ( 'http://localhost:80/' ) ;
71+ } ) ;
72+
6773 it ( 'Different instances for different URLs' , function ( ) {
6874 var db1 = defaultApp . database ( 'http://foo1.bar.com' ) ;
6975 var db2 = defaultApp . database ( 'http://foo2.bar.com' ) ;
You can’t perform that action at this time.
0 commit comments