mirror of
https://github.com/getnamingo/registry.git
synced 2025-07-04 10:03:19 +02:00
Fixed issue with single character domains
This commit is contained in:
parent
4658913847
commit
d7e7408072
2 changed files with 25 additions and 13 deletions
|
@ -229,15 +229,19 @@ function validate_label($domain, $db) {
|
||||||
|
|
||||||
// Split domain into labels (subdomains, SLD, TLD)
|
// Split domain into labels (subdomains, SLD, TLD)
|
||||||
$labels = explode('.', $domain);
|
$labels = explode('.', $domain);
|
||||||
foreach ($labels as $label) {
|
|
||||||
$len = strlen($label);
|
|
||||||
|
|
||||||
// Labels cannot be empty, shorter than 2, or longer than 63 characters
|
if (count($labels) > 1) { // Ensure there is at least an SLD and TLD
|
||||||
|
$firstLabel = $labels[0];
|
||||||
|
$len = strlen($firstLabel);
|
||||||
|
|
||||||
|
// Label cannot be empty, shorter than 2, or longer than 63 characters
|
||||||
if ($len < 2 || $len > 63) {
|
if ($len < 2 || $len > 63) {
|
||||||
return 'Each domain label must be between 2 and 63 characters';
|
return 'The domain label must be between 2 and 63 characters';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!preg_match('/^[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]$/', $label)) {
|
foreach ($labels as $label) {
|
||||||
|
if (!preg_match('/^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?$/', $label)) {
|
||||||
return 'Each domain label must start and end with a letter or number and contain only letters, numbers, or hyphens';
|
return 'Each domain label must start and end with a letter or number and contain only letters, numbers, or hyphens';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -234,12 +234,20 @@ function validate_label($domain, $pdo) {
|
||||||
|
|
||||||
// Split domain into labels (subdomains, SLD, TLD)
|
// Split domain into labels (subdomains, SLD, TLD)
|
||||||
$labels = explode('.', $domain);
|
$labels = explode('.', $domain);
|
||||||
foreach ($labels as $label) {
|
|
||||||
$len = strlen($label);
|
|
||||||
|
|
||||||
// Labels cannot be empty, shorter than 2, or longer than 63 characters
|
if (count($labels) > 1) { // Ensure there is at least an SLD and TLD
|
||||||
|
$firstLabel = $labels[0];
|
||||||
|
$len = strlen($firstLabel);
|
||||||
|
|
||||||
|
// Label cannot be empty, shorter than 2, or longer than 63 characters
|
||||||
if ($len < 2 || $len > 63) {
|
if ($len < 2 || $len > 63) {
|
||||||
return 'Each domain label must be between 2 and 63 characters';
|
return 'The domain label must be between 2 and 63 characters';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($labels as $label) {
|
||||||
|
if (!preg_match('/^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?$/', $label)) {
|
||||||
|
return 'Each domain label must start and end with a letter or number and contain only letters, numbers, or hyphens';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!preg_match('/^[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]$/', $label)) {
|
if (!preg_match('/^[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]$/', $label)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue