From 74d54dcddbd06e5598586f125e0aeb58b25c6733 Mon Sep 17 00:00:00 2001 From: Laminas Bot Date: Mon, 12 Jun 2023 01:20:15 +0000 Subject: [PATCH 1/3] Update TLD list for hostname validator Signed-off-by: Laminas Bot --- src/Hostname.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Hostname.php b/src/Hostname.php index 5c1101d9..172e8689 100644 --- a/src/Hostname.php +++ b/src/Hostname.php @@ -89,7 +89,7 @@ class Hostname extends AbstractValidator /** * Array of valid top-level-domains - * IanaVersion 2023060100 + * IanaVersion 2023061100 * * @see ftp://data.iana.org/TLD/tlds-alpha-by-domain.txt List of all TLDs by domain * @see http://www.iana.org/domains/root/db/ Official list of supported TLDs @@ -99,7 +99,6 @@ class Hostname extends AbstractValidator protected $validTlds = [ 'aaa', 'aarp', - 'abarth', 'abb', 'abbott', 'abbvie', @@ -134,7 +133,6 @@ class Hostname extends AbstractValidator 'airtel', 'akdn', 'al', - 'alfaromeo', 'alibaba', 'alipay', 'allfinanz', @@ -508,7 +506,6 @@ class Hostname extends AbstractValidator 'ferrari', 'ferrero', 'fi', - 'fiat', 'fidelity', 'fido', 'film', @@ -775,7 +772,6 @@ class Hostname extends AbstractValidator 'lamborghini', 'lamer', 'lancaster', - 'lancia', 'land', 'landrover', 'lanxess', @@ -849,7 +845,6 @@ class Hostname extends AbstractValidator 'markets', 'marriott', 'marshalls', - 'maserati', 'mattel', 'mba', 'mc', From 7bee1dbe61c5634cc1e46089c877a56b8d1d7180 Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Mon, 12 Jun 2023 19:18:23 +1000 Subject: [PATCH 2/3] Drop IanaVersion from Hostname validator comment Signed-off-by: Aleksei Khudiakov --- src/Hostname.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Hostname.php b/src/Hostname.php index 172e8689..29ac60e5 100644 --- a/src/Hostname.php +++ b/src/Hostname.php @@ -89,7 +89,6 @@ class Hostname extends AbstractValidator /** * Array of valid top-level-domains - * IanaVersion 2023061100 * * @see ftp://data.iana.org/TLD/tlds-alpha-by-domain.txt List of all TLDs by domain * @see http://www.iana.org/domains/root/db/ Official list of supported TLDs From ce7afa7257c52166ebcd66af5d596fcd9b2dfdbe Mon Sep 17 00:00:00 2001 From: Aleksei Khudiakov Date: Mon, 12 Jun 2023 19:24:21 +1000 Subject: [PATCH 3/3] Update IANA TLD list updater script to drop IanaVersion comment Signed-off-by: Aleksei Khudiakov --- bin/update_hostname_validator.php | 65 ++++++++++--------------------- 1 file changed, 20 insertions(+), 45 deletions(-) diff --git a/bin/update_hostname_validator.php b/bin/update_hostname_validator.php index 25e4d38d..0a9b49c6 100644 --- a/bin/update_hostname_validator.php +++ b/bin/update_hostname_validator.php @@ -20,34 +20,15 @@ } /** @psalm-var list $newFileContent */ -$newFileContent = []; // new file content -$insertDone = false; // becomes 'true' when we find start of $validTlds declaration -$insertFinish = false; // becomes 'true' when we find end of $validTlds declaration -$checkOnly = isset($argv[1]) ? $argv[1] === '--check-only' : false; -$response = getOfficialTLDs(); -$ianaVersion = getVersionFromString('Version', strtok($response, "\n")); -$validatorVersion = getVersionFromString('IanaVersion', file_get_contents(LAMINAS_HOSTNAME_VALIDATOR_FILE)); - -if ($checkOnly && $ianaVersion > $validatorVersion) { - printf( - 'TLDs must be updated, please run `php bin/update_hostname_validator.php` and push your changes%s', - PHP_EOL - ); - exit(1); -} - -if ($checkOnly) { - printf('TLDs are up-to-date%s', PHP_EOL); - exit(0); -} +$newFileContent = []; // new file content +$insertDone = false; // becomes 'true' when we find start of $validTlds declaration +$insertFinish = false; // becomes 'true' when we find end of $validTlds declaration +$checkOnly = isset($argv[1]) ? $argv[1] === '--check-only' : false; +$response = getOfficialTLDs(); -foreach (file(LAMINAS_HOSTNAME_VALIDATOR_FILE) as $line) { - // Replace old version number with new one - if (preg_match('/\*\s+IanaVersion\s+\d+/', $line, $matches)) { - $newFileContent[] = sprintf(" * IanaVersion %s\n", $ianaVersion); - continue; - } +$currentFileContent = file(LAMINAS_HOSTNAME_VALIDATOR_FILE); +foreach ($currentFileContent as $line) { if ($insertDone === $insertFinish) { // Outside of $validTlds definition; keep line as-is $newFileContent[] = $line; @@ -84,6 +65,19 @@ exit(1); } +if ($currentFileContent === $newFileContent) { + printf('Nothing to do. Validator has no TLD changes.%s', PHP_EOL); + exit(0); +} + +if ($checkOnly) { + printf( + 'TLDs must be updated, please run `php bin/update_hostname_validator.php` and push your changes%s', + PHP_EOL + ); + exit(1); +} + if (false === @file_put_contents(LAMINAS_HOSTNAME_VALIDATOR_FILE, $newFileContent)) { printf('Error: cannot write info file "%s"%s', LAMINAS_HOSTNAME_VALIDATOR_FILE, PHP_EOL); exit(1); @@ -109,25 +103,6 @@ function getOfficialTLDs(): string } } -/** - * Extract the first match of a string like - * "Version 2015072300" from the given string - * - * @param string $prefix - * @param string $string - * @return string - * @throws Exception - */ -function getVersionFromString($prefix, $string) -{ - $matches = []; - if (! preg_match(sprintf('/%s\s+((\d+)?)/', $prefix), $string, $matches)) { - throw new Exception('Error: cannot get last update date'); - } - - return $matches[1]; -} - /** * Extract new Valid TLDs from a string containing one per line. *