Made blank server address validation stricter
Some checks failed
build-docker / build (push) Has been cancelled
build / build (push) Has been cancelled

This commit is contained in:
RaphiMC 2024-10-30 22:32:46 +01:00
parent 1287cb2f9f
commit 3bb37e3f0e
No known key found for this signature in database
GPG key ID: 0F6BB0657A03AC94

View file

@ -31,16 +31,16 @@ import java.net.SocketAddress;
public class AddressUtil {
public static SocketAddress parse(final String serverAddress, final ProtocolVersion version) {
if (serverAddress.isBlank()) {
throw new IllegalArgumentException("Server address cannot be blank");
}
if (serverAddress.startsWith("file:///") || serverAddress.startsWith("unix:///")) { // Unix Socket
final String filePath = serverAddress.substring(7);
return new DomainSocketAddress(filePath);
} else { // IP Address
final HostAndPort hostAndPort = HostAndPort.fromString(serverAddress);
if (hostAndPort.getHost().isBlank()) {
throw new IllegalArgumentException("Server address cannot be blank");
}
final int port;
if (version != null) {
port = hostAndPort.getPortOrDefault(getDefaultPort(version));