Fix fatal error in some environments when relative URL is passed to encodeIdna() or decodeIdna() #2675

This commit is contained in:
Kijin Sung 2026-02-11 20:54:00 +09:00
parent 1199095e7f
commit 5834a3c18a

View file

@ -207,9 +207,13 @@ class URL
*/
public static function encodeIdna(string $url): string
{
if (preg_match('@[:/#]@', $url))
if (preg_match('@[:/#]@', $url) && !str_starts_with($url, '/'))
{
$domain = parse_url($url, \PHP_URL_HOST);
if (!$domain)
{
return $url;
}
$position = strpos($url, $domain);
if ($position === false)
{
@ -243,9 +247,13 @@ class URL
*/
public static function decodeIdna(string $url): string
{
if (preg_match('@[:/#]@', $url))
if (preg_match('@[:/#]@', $url) && !str_starts_with($url, '/'))
{
$domain = parse_url($url, \PHP_URL_HOST);
if (!$domain)
{
return $url;
}
$position = strpos($url, $domain);
if ($position === false)
{