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. * diff --git a/src/Hostname.php b/src/Hostname.php index 5c1101d9..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 2023060100 * * @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 +98,6 @@ class Hostname extends AbstractValidator protected $validTlds = [ 'aaa', 'aarp', - 'abarth', 'abb', 'abbott', 'abbvie', @@ -134,7 +132,6 @@ class Hostname extends AbstractValidator 'airtel', 'akdn', 'al', - 'alfaromeo', 'alibaba', 'alipay', 'allfinanz', @@ -508,7 +505,6 @@ class Hostname extends AbstractValidator 'ferrari', 'ferrero', 'fi', - 'fiat', 'fidelity', 'fido', 'film', @@ -775,7 +771,6 @@ class Hostname extends AbstractValidator 'lamborghini', 'lamer', 'lancaster', - 'lancia', 'land', 'landrover', 'lanxess', @@ -849,7 +844,6 @@ class Hostname extends AbstractValidator 'markets', 'marriott', 'marshalls', - 'maserati', 'mattel', 'mba', 'mc',