1616 * limitations under the License.
1717 */
1818
19- import ParsedUrl from 'url-parse ' ;
19+ import { parse as uriJsParse } from 'uri-js ' ;
2020import { assertString } from './util' ;
2121
2222const DEFAULT_BOLT_PORT = 7687 ;
@@ -68,14 +68,14 @@ function parseDatabaseUrl(url) {
6868 assertString ( url , 'URL' ) ;
6969
7070 const sanitized = sanitizeUrl ( url ) ;
71- const parsedUrl = new ParsedUrl ( sanitized . url , { } , query => extractQuery ( query , url ) ) ;
71+ const parsedUrl = uriJsParse ( sanitized . url ) ;
7272
73- const scheme = sanitized . schemeMissing ? null : extractScheme ( parsedUrl . protocol ) ;
74- const rawHost = extractHost ( parsedUrl . hostname ) ; // has square brackets for IPv6
75- const host = unescapeIPv6Address ( rawHost ) ; // no square brackets for IPv6
73+ const scheme = sanitized . schemeMissing ? null : extractScheme ( parsedUrl . scheme ) ;
74+ const host = extractHost ( parsedUrl . host ) ; // no square brackets for IPv6
75+ const formattedHost = formatHost ( host ) ; // has square brackets for IPv6
7676 const port = extractPort ( parsedUrl . port , scheme ) ;
77- const hostAndPort = `${ rawHost } :${ port } ` ;
78- const query = parsedUrl . query ;
77+ const hostAndPort = `${ formattedHost } :${ port } ` ;
78+ const query = extractQuery ( parsedUrl . query , url ) ;
7979
8080 return new Url ( scheme , host , port , hostAndPort , query ) ;
8181}
@@ -84,8 +84,8 @@ function sanitizeUrl(url) {
8484 url = url . trim ( ) ;
8585
8686 if ( url . indexOf ( '://' ) === - 1 ) {
87- // url does not contain scheme, add dummy 'http ://' to make parser work correctly
88- return { schemeMissing : true , url : `http ://${ url } ` } ;
87+ // url does not contain scheme, add dummy 'none ://' to make parser work correctly
88+ return { schemeMissing : true , url : `none ://${ url } ` } ;
8989 }
9090
9191 return { schemeMissing : false , url : url } ;
@@ -168,17 +168,12 @@ function escapeIPv6Address(address) {
168168 }
169169}
170170
171- function unescapeIPv6Address ( address ) {
172- const startsWithSquareBracket = address . charAt ( 0 ) === '[' ;
173- const endsWithSquareBracket = address . charAt ( address . length - 1 ) === ']' ;
174-
175- if ( ! startsWithSquareBracket && ! endsWithSquareBracket ) {
176- return address ;
177- } else if ( startsWithSquareBracket && endsWithSquareBracket ) {
178- return address . substring ( 1 , address . length - 1 ) ;
179- } else {
180- throw new Error ( `Illegal IPv6 address ${ address } ` ) ;
171+ function formatHost ( host ) {
172+ if ( ! host ) {
173+ throw new Error ( `Illegal host ${ host } ` ) ;
181174 }
175+ const isIPv6Address = host . indexOf ( ':' ) >= 0 ;
176+ return isIPv6Address ? escapeIPv6Address ( host ) : host ;
182177}
183178
184179function formatIPv4Address ( address , port ) {
0 commit comments