network: Normalize IP parsing, fix IPv6, tests

This commit is contained in:
Fabio Alessandrelli
2026-01-09 14:48:21 +01:00
parent 1910c58c49
commit 65ce1360b4
5 changed files with 431 additions and 134 deletions

View File

@@ -35,6 +35,7 @@ STATIC_ASSERT_INCOMPLETE_TYPE(class, Dictionary);
STATIC_ASSERT_INCOMPLETE_TYPE(class, Object);
#include "core/crypto/crypto_core.h"
#include "core/io/ip_address.h"
#include "core/math/color.h"
#include "core/math/math_funcs.h"
#include "core/object/object.h"
@@ -4940,43 +4941,7 @@ String String::validate_filename() const {
}
bool String::is_valid_ip_address() const {
if (find_char(':') >= 0) {
Vector<String> ip = split(":");
for (int i = 0; i < ip.size(); i++) {
const String &n = ip[i];
if (n.is_empty()) {
continue;
}
if (n.is_valid_hex_number(false)) {
int64_t nint = n.hex_to_int();
if (nint < 0 || nint > 0xffff) {
return false;
}
continue;
}
if (!n.is_valid_ip_address()) {
return false;
}
}
} else {
Vector<String> ip = split(".");
if (ip.size() != 4) {
return false;
}
for (int i = 0; i < ip.size(); i++) {
const String &n = ip[i];
if (!n.is_valid_int()) {
return false;
}
int val = n.to_int();
if (val < 0 || val > 255) {
return false;
}
}
}
return true;
return IPAddress::is_valid_ip_address(*this);
}
bool String::is_resource_file() const {