Don't crash when using invalid characters in host name (#7791)

This commit is contained in:
ByteHamster 2025-04-30 22:58:52 +02:00 committed by GitHub
parent fe524237d4
commit 42d62ab57a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -19,7 +19,11 @@ public class HostnameParser {
Matcher m = URLSPLIT_REGEX.matcher(hosturl);
if (m.matches()) {
scheme = m.group(1);
host = IDN.toASCII(m.group(2));
try {
host = IDN.toASCII(m.group(2));
} catch (IllegalArgumentException e) {
host = "invalid-hostname";
}
if (m.group(3) == null) {
port = -1;
} else {
@ -33,7 +37,11 @@ public class HostnameParser {
} else {
// URL does not match regex: use it anyway -> this will cause an exception on connect
scheme = "https";
host = IDN.toASCII(hosturl);
try {
host = IDN.toASCII(hosturl);
} catch (IllegalArgumentException e) {
host = "invalid-hostname";
}
port = 443;
}