-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ba6a7f
commit 65f3067
Showing
1 changed file
with
19 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,12 +138,13 @@ public static function filterDomain(mixed $domainName): ?string | |
// get domain name if the given argument is an url | ||
// protocol://user:[email protected]:port/path | ||
if (preg_match( | ||
'~^(?:(?:[a-z]+:)?//)?(?:[^:]*(?::[^@]*)?@)?([^/]+)(?::\d+|[#?/]|$)~', | ||
'~^(?:(?:[a-z]+:)?//)?(?:[^:]*(?::[^@]*)?@)?([^/:]+)(?::\d+|[#?/]|$)~', | ||
$domainName, | ||
$match | ||
)) { | ||
$domainName = $match[1]; | ||
} | ||
|
||
if ($domainName === 'localhost') { | ||
return $domainName; | ||
} | ||
|
@@ -187,31 +188,36 @@ public static function filterDomain(mixed $domainName): ?string | |
if ($intl_idn) { | ||
$domainName = $isAscii ? idn_to_utf8($domainName) : idn_to_ascii($domainName); | ||
// revert | ||
return ($isAscii ? idn_to_ascii($domainName) : idn_to_utf8($domainName)) ?: null; | ||
} | ||
|
||
foreach ($labels as &$label) { | ||
if (preg_match('/[^x00-x7F]/', $domainName)) { | ||
$label = 'xn--'.self::punycodeEncode($label); | ||
if (!$label || strlen($label) > 63) { | ||
return null; | ||
$domainName = ($isAscii ? idn_to_ascii($domainName) : idn_to_utf8($domainName)) ?: null; | ||
if (!$domainName) { | ||
return null; | ||
} | ||
$labels = $domainName; | ||
} else { | ||
foreach ($labels as &$label) { | ||
if (preg_match('/[^x00-x7F]/', $domainName)) { | ||
$label = 'xn--' . self::punycodeEncode($label); | ||
if (!$label || strlen($label) > 63) { | ||
return null; | ||
} | ||
} | ||
} | ||
unset($label); | ||
$labels = implode('.', $labels); | ||
} | ||
|
||
unset($label); | ||
$labels = implode('.', $labels); | ||
if (strlen($labels) > 255 | ||
|| strlen($labels) < 2 | ||
// domain except localhost should contain extension | ||
// xn-- // (?i)[a-z0-9-] | ||
|| !preg_match( | ||
'~[a-z0-9\-](?:[a-z0-9-]*[a-z0-9]+(?:\.[a-z0-9-]*[a-z0-9]+)*)?$~', | ||
'~[a-z0-9\-](?:[a-z0-9-]*[a-z0-9]+(?:\.[a-z0-9-]*[a-z0-9]+)*)?\.(?:xn--[a-z0-9_]+|[a-z]+)$~', | ||
$labels | ||
) | ||
) { | ||
return null; | ||
} | ||
|
||
|
||
return $domainName; | ||
} | ||
|
||
|