Fallback mechanism for missing IDN functions

This commit is contained in:
Michael 2024-04-06 09:20:23 +00:00
parent e9dcf15d86
commit 78dc61b59e
6 changed files with 58 additions and 32 deletions

View file

@ -533,20 +533,29 @@ class Network
{
$parts = parse_url($uri);
if (!empty($parts['scheme']) && !empty($parts['host'])) {
$parts['host'] = idn_to_ascii($parts['host']);
$parts['host'] = self::idnToAscii($parts['host']);
$uri = (string)Uri::fromParts($parts);
} else {
$parts = explode('@', $uri);
if (count($parts) == 2) {
$uri = $parts[0] . '@' . idn_to_ascii($parts[1]);
$uri = $parts[0] . '@' . self::idnToAscii($parts[1]);
} else {
$uri = idn_to_ascii($uri);
$uri = self::idnToAscii($uri);
}
}
return $uri;
}
private static function idnToAscii(string $uri): string
{
if (!function_exists('idn_to_ascii')) {
Logger::error('IDN functions are missing.');
return $uri;
}
return idn_to_ascii($uri);
}
/**
* Switch the scheme of an url between http and https
*