1
0
mirror of https://github.com/danog/dns.git synced 2024-11-27 04:24:48 +01:00

Support final dot in DNS names (#83)

This commit is contained in:
Daniil Gentili 2019-06-13 18:38:24 +02:00 committed by Niklas Keller
parent 498c7d3486
commit fbf1ae2d89

View File

@ -84,7 +84,7 @@ function isValidName(string $name)
*/
function normalizeName(string $name): string
{
static $pattern = '/^(?<name>[a-z0-9]([a-z0-9-_]{0,61}[a-z0-9])?)(\.(?&name))*$/i';
static $pattern = '/^(?<name>[a-z0-9]([a-z0-9-_]{0,61}[a-z0-9])?)(\.(?&name))*\.?$/i';
if (\function_exists('idn_to_ascii') && \defined('INTL_IDNA_VARIANT_UTS46')) {
if (false === $result = \idn_to_ascii($name, 0, \INTL_IDNA_VARIANT_UTS46)) {
@ -102,6 +102,8 @@ function normalizeName(string $name): string
if (isset($name[253]) || !\preg_match($pattern, $name)) {
throw new InvalidNameException("Name '{$name}' is not a valid hostname.");
}
if ($name[\strlen($name)-1] === '.') {
$name = \substr($name, 0, -1);
}
return $name;
}