diff --git a/cp/bootstrap/helper.php b/cp/bootstrap/helper.php index cf3c6f6..e64499a 100644 --- a/cp/bootstrap/helper.php +++ b/cp/bootstrap/helper.php @@ -360,9 +360,18 @@ function extractDomainAndTLD($urlString) { } // Use the PHP Domain Parser library for real TLDs - $tlds = TopLevelDomains::fromString($fileContent); - $domain = Domain::fromIDNA2008($host); - $resolvedTLD = $tlds->resolve($domain)->suffix()->toString(); + try { + // Use the PHP Domain Parser library for real TLDs + $tlds = TopLevelDomains::fromString($fileContent); + $domain = Domain::fromIDNA2008($host); + $resolvedTLD = $tlds->resolve($domain)->suffix()->toString(); + } catch (\Pdp\Exception $e) { // Catch domain parser exceptions + $_SESSION['slimFlash']['error'][] = 'Domain parsing error: ' . $e->getMessage(); + return ['error' => 'Domain parsing error: ' . $e->getMessage()]; + } catch (\Exception $e) { // Catch any other unexpected exceptions + $_SESSION['slimFlash']['error'][] = 'Unexpected error: ' . $e->getMessage(); + return ['error' => 'Unexpected error: ' . $e->getMessage()]; + } // Handle cases with multi-level TLDs $possibleTLDs = []; diff --git a/epp/src/helpers.php b/epp/src/helpers.php index 3904c85..0f43a5a 100644 --- a/epp/src/helpers.php +++ b/epp/src/helpers.php @@ -300,10 +300,16 @@ function extractDomainAndTLD($urlString) { return $result; } - // Use the PHP Domain Parser library for real TLDs - $tlds = TopLevelDomains::fromString($fileContent); - $domain = Domain::fromIDNA2008($host); - $resolvedTLD = $tlds->resolve($domain)->suffix()->toString(); + try { + // Use the PHP Domain Parser library for real TLDs + $tlds = TopLevelDomains::fromString($fileContent); + $domain = Domain::fromIDNA2008($host); + $resolvedTLD = $tlds->resolve($domain)->suffix()->toString(); + } catch (\Pdp\Exception $e) { // Catch domain parser exceptions + throw new \Exception('Domain parsing error: ' . $e->getMessage()); + } catch (\Exception $e) { // Catch any other unexpected exceptions + throw new \Exception('Unexpected error: ' . $e->getMessage()); + } // Handle cases with multi-level TLDs $possibleTLDs = [];