Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions src/Handlers/AbstractDnsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,12 @@ protected function validateHostName(string $hostName): void

$hostnameErrorInfo = 'Invalid hostname ' . json_encode($hostName);

if (strlen($hostName) < 3) {
if (!filter_var($hostName, FILTER_VALIDATE_DOMAIN)) {
throw new DnsHandlerException(
$hostnameErrorInfo . ' length. It must be 3 or more!',
DnsHandlerException::HOSTNAME_LENGTH_TOO_SMALL
);
}

if (!preg_match(Regex::DOMAIN_OR_SUBDOMAIN, $hostName)) {
throw new DnsHandlerException(
$hostnameErrorInfo . ' format! (characters "A-Za-z0-9.-", max length 63 chars allowed)',
$hostnameErrorInfo . ' format!',
DnsHandlerException::HOSTNAME_FORMAT_INVALID
);
}

if (!preg_match(Regex::HOSTNAME_LENGTH, $hostName)) {
throw new DnsHandlerException(
$hostnameErrorInfo . ' length! (min 3, max 253 characters allowed)',
DnsHandlerException::HOSTNAME_LENGTH_INVALID
);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Records/DnsUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static function isValidDomainOrSubdomain(string $domain): bool
if (empty($domain) || strlen($domain) < 4) {
return false;
}
return preg_match(Regex::DOMAIN_OR_SUBDOMAIN, $domain) === 1;
return (bool) filter_var($domain, FILTER_VALIDATE_DOMAIN);
}

public static function ipV6Shortener(string $ipv6): string
Expand Down
2 changes: 1 addition & 1 deletion src/Records/ExtendedTxtRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function isParentHostName($host): bool
*/
private function isDomainOrSubdomainHostName(string $host): bool
{
return preg_match(Regex::DOMAIN_OR_SUBDOMAIN, $host) === 1;
return (bool) filter_var($host, FILTER_VALIDATE_DOMAIN);
}

private function isDomainKeyHostName(string $host): bool
Expand Down
3 changes: 0 additions & 3 deletions src/Regex.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

class Regex
{
public const DOMAIN_OR_SUBDOMAIN = '/^(([\w\d\_\-]+){1,63}\.)+(\w+){2,63}$/i';
public const HOSTNAME_LENGTH = '/^.{3,253}$/';

public const SPF_VALIDATION = '/^v=spf1 ([a-z0-9:.\/ ~\-_\+]+)/i';

public const DKIM_SELECTOR_VALUE = '/^([\w\_]+)\._domainkey.*/';
Expand Down