This commit is contained in:
Pinga 2023-12-30 15:20:01 +02:00
parent 4503cd0073
commit 3605eaece8
4 changed files with 33 additions and 9 deletions

View file

@ -291,17 +291,29 @@ function extractDomainAndTLD($urlString) {
$parts = parse_url($urlString);
$host = $parts['host'] ?? $urlString;
// Sort test TLDs by length (longest first) to match the longest possible TLD
usort($testTlds, function ($a, $b) {
return strlen($b) - strlen($a);
});
// Check if the TLD is a known test TLD
foreach ($testTlds as $testTld) {
if (str_ends_with($host, "$testTld")) {
// Handle the test TLD case
$hostParts = explode('.', $host);
$tld = array_pop($hostParts);
$tldLength = strlen($testTld) + 1; // +1 for the dot
$hostWithoutTld = substr($host, 0, -$tldLength);
$hostParts = explode('.', $hostWithoutTld);
$sld = array_pop($hostParts);
return ['domain' => $sld, 'tld' => $tld];
if (strpos($testTld, '.') === 0) {
$testTld = ltrim($testTld, '.');
}
return [
'domain' => implode('.', $hostParts) ? implode('.', $hostParts) . '.' . $sld : $sld,
'tld' => $testTld
];
}
}
// Use the PHP Domain Parser library for real TLDs
$tlds = TopLevelDomains::fromString($fileContent);
$domain = Domain::fromIDNA2008($host);

View file

@ -26,4 +26,4 @@ MAIL_API_PROVIDER='sendgrid'
STRIPE_SECRET_KEY='stripe-secret-key'
TEST_TLDS=.test,.xx
TEST_TLDS=.test,.com.test

View file

@ -14,5 +14,5 @@ return [
'epp_prefix' => 'namingo',
'ssl_cert' => '',
'ssl_key' => '',
'test_tlds' => '.test,.xx',
'test_tlds' => '.test,.com.test',
];

View file

@ -247,15 +247,27 @@ function extractDomainAndTLD($urlString) {
// Parse the URL to get the host
$parts = parse_url($urlString);
$host = $parts['host'] ?? $urlString;
// Sort test TLDs by length (longest first) to match the longest possible TLD
usort($testTlds, function ($a, $b) {
return strlen($b) - strlen($a);
});
// Check if the TLD is a known test TLD
foreach ($testTlds as $testTld) {
if (str_ends_with($host, "$testTld")) {
// Handle the test TLD case
$hostParts = explode('.', $host);
$tld = array_pop($hostParts);
$tldLength = strlen($testTld) + 1; // +1 for the dot
$hostWithoutTld = substr($host, 0, -$tldLength);
$hostParts = explode('.', $hostWithoutTld);
$sld = array_pop($hostParts);
return ['domain' => $sld, 'tld' => $tld];
if (strpos($testTld, '.') === 0) {
$testTld = ltrim($testTld, '.');
}
return [
'domain' => implode('.', $hostParts) ? implode('.', $hostParts) . '.' . $sld : $sld,
'tld' => $testTld
];
}
}