File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed
reverse_engineering/helpers Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ function escapeV6IpForURL({ host }) {
22
22
* !ip.isV4Format(host) check required because isV6Format returns true for ipv4 address because of backward compatibility
23
23
*/
24
24
if ( ip . isV6Format ( host ) && ! ip . isV4Format ( host ) ) {
25
- return `[ ${ host } ]` ;
25
+ return escapeHost ( host ) ;
26
26
}
27
27
28
28
const isUrlValid = isValidURL ( host ) ;
@@ -42,7 +42,20 @@ function escapeV6IpForURL({ host }) {
42
42
const port = separatedIpPortionsAndPort . at ( - 1 ) ;
43
43
const escapedIpWithPort = `[${ ipPortions . join ( ':' ) } ]:${ port } ` ;
44
44
45
- return host . replace ( unescapedIpWithPort , escapedIpWithPort ) ;
45
+ const hostWithEscapedAllPortionsButTheLastOne = host . replace ( unescapedIpWithPort , escapedIpWithPort ) ;
46
+ if ( isValidURL ( hostWithEscapedAllPortionsButTheLastOne ) ) {
47
+ return hostWithEscapedAllPortionsButTheLastOne ;
48
+ }
49
+
50
+ return host . replace ( unescapedIpWithPort , escapeHost ( unescapedIpWithPort ) ) ;
51
+ }
52
+
53
+ /**
54
+ * @param {string } host
55
+ * @returns {string }
56
+ */
57
+ function escapeHost ( host ) {
58
+ return `[${ host } ]` ;
46
59
}
47
60
48
61
/**
You can’t perform that action at this time.
0 commit comments