From 54f53e26637436aac08ddca298a4143ff892a60b Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 14 May 2019 19:09:51 +0200 Subject: [PATCH] Support final dot for DNS names --- lib/functions.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/functions.php b/lib/functions.php index 1002e18..e649481 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -84,7 +84,7 @@ function isValidName(string $name) */ function normalizeName(string $name): string { - static $pattern = '/^(?[a-z0-9]([a-z0-9-_]{0,61}[a-z0-9])?)(\.(?&name))*$/i'; + static $pattern = '/^(?[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; }