File tree Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,9 @@ function escapeV6IpForURL({ host }) {
30
30
return host ;
31
31
}
32
32
33
- const urlWithIpV6HostRegExp = new RegExp ( / ^ h t t p ( s ) ? : \/ \/ (?< unescapedIpWithPort > ( [ a - z 0 - 9 ] { 0 , 4 } : ? ) + ) / gim) ;
33
+ const urlWithIpV6HostRegExp = new RegExp (
34
+ / ^ ( h t t p ( s ) ? | ( n e o 4 j ( \+ s | s | ) ( \+ s s c | s s c | ) ) | b o l t ) : \/ \/ (?< unescapedIpWithPort > ( [ a - z 0 - 9 ] { 0 , 4 } : ? ) + ) / gim,
35
+ ) ;
34
36
const { unescapedIpWithPort } = urlWithIpV6HostRegExp . exec ( host ) ?. groups ?? { } ;
35
37
36
38
if ( ! unescapedIpWithPort ) {
@@ -42,7 +44,13 @@ function escapeV6IpForURL({ host }) {
42
44
const port = separatedIpPortionsAndPort . at ( - 1 ) ;
43
45
const escapedIpWithPort = `[${ ipPortions . join ( ':' ) } ]:${ port } ` ;
44
46
45
- return host . replace ( unescapedIpWithPort , escapedIpWithPort ) ;
47
+ const replacedHost = host . replace ( unescapedIpWithPort , escapedIpWithPort ) ;
48
+
49
+ if ( isValidURL ( replacedHost ) ) {
50
+ return replacedHost ;
51
+ }
52
+
53
+ return host . replace ( unescapedIpWithPort , `[${ unescapedIpWithPort } ]` ) ;
46
54
}
47
55
48
56
/**
@@ -54,7 +62,8 @@ function isValidURL(url) {
54
62
new URL ( url ) ;
55
63
56
64
return true ;
57
- } catch {
65
+ } catch ( error ) {
66
+ console . error ( error ) ;
58
67
return false ;
59
68
}
60
69
}
Original file line number Diff line number Diff line change @@ -431,13 +431,13 @@ const getConnectionURI = info => {
431
431
if ( neo4jProtocolRegex . test ( info . host ) ) {
432
432
host = info . host ;
433
433
} else {
434
- host = `bolt://${ escapeV6IpForURL ( { host : info . host } ) } ` ;
434
+ host = `bolt://${ info . host } ` ;
435
435
}
436
436
if ( info . port ) {
437
- host = `${ escapeV6IpForURL ( { host : info . host } ) } :${ info . port } ` ;
437
+ host = `${ host } :${ info . port } ` ;
438
438
}
439
439
440
- return host ;
440
+ return escapeV6IpForURL ( { host } ) ;
441
441
} ;
442
442
443
443
module . exports = {
You can’t perform that action at this time.
0 commit comments