Skip to content

Commit

Permalink
Work on #52
Browse files Browse the repository at this point in the history
  • Loading branch information
getpinga committed Dec 30, 2023
1 parent 4503cd0 commit 3605eae
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
20 changes: 16 additions & 4 deletions cp/bootstrap/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion cp/env-sample
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ MAIL_API_PROVIDER='sendgrid'

STRIPE_SECRET_KEY='stripe-secret-key'

TEST_TLDS=.test,.xx
TEST_TLDS=.test,.com.test
2 changes: 1 addition & 1 deletion epp/config.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ return [
'epp_prefix' => 'namingo',
'ssl_cert' => '',
'ssl_key' => '',
'test_tlds' => '.test,.xx',
'test_tlds' => '.test,.com.test',
];
18 changes: 15 additions & 3 deletions epp/src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
];
}
}

Expand Down

0 comments on commit 3605eae

Please sign in to comment.