Merge pull request #7310 from alvasw/NodeAddress_Fix_broken_IPV6_parsing

NodeAddress: Fix broken IPV6 parsing
This commit is contained in:
Alejandro García 2024-11-20 05:46:24 +00:00 committed by GitHub
commit ab9385db8f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -47,10 +47,19 @@ public final class NodeAddress implements PersistablePayload, NetworkPayload, Us
}
public NodeAddress(String fullAddress) {
final String[] split = fullAddress.split(Pattern.quote(":"));
checkArgument(split.length == 2, "fullAddress must contain ':'");
this.hostName = split[0];
this.port = Integer.parseInt(split[1]);
String[] split = fullAddress.split("]");
boolean isIpV6Address = split.length == 2 && fullAddress.startsWith("[");
if (isIpV6Address) {
this.hostName = split[0].replace("[", "");
String portString = split[1].replace(":", "");
this.port = Integer.parseInt(portString);
} else {
split = fullAddress.split(Pattern.quote(":"));
checkArgument(split.length == 2, "fullAddress must contain ':'");
this.hostName = split[0];
this.port = Integer.parseInt(split[1]);
}
}