Skip to content

Commit e83c5c0

Browse files
committed
domain validation fix
1 parent d30f9d1 commit e83c5c0

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

func/main.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,16 +463,24 @@ sync_cron_jobs() {
463463

464464
# User format validator
465465
is_user_format_valid() {
466-
if ! [[ "$1" =~ ^[a-zA-Z0-9][-|\.|_|a-zA-Z0-9]{0,28}[a-zA-Z0-9]$ ]]; then
467-
check_result $E_INVALID "invalid $2 format :: $1"
466+
if [ ${#1} -eq 1 ]; then
467+
if ! [[ "$1" =~ ^^[[:alnum:]]$ ]]; then
468+
echo "invalid $2 format :: $1"
469+
fi
470+
else
471+
if ! [[ "$1" =~ ^[[:alnum:]][-|\.|_[:alnum:]]{0,28}[[:alnum:]]$ ]]
472+
then
473+
echo "invalid $2 format :: $1"
474+
fi
468475
fi
469476
}
470477

471478
# Domain format validator
472479
is_domain_format_valid() {
473480
object_name=${2-domain}
474-
exclude="[!|@|#|$|^|&|*|(|)|+|=|{|}|:|,|<|>|?|_|/|\|\"|'|;|%|\`| ]"
475-
if [[ "$1" =~ $exclude ]]; then
481+
mask1='(([[:alnum:]](-?[[:alnum:]])*)\.)'
482+
mask2='*[[:alnum:]](-?[[:alnum:]])+\.[[:alnum:]]{2,}'
483+
if ! [[ "$1" =~ ^${mask1}${mask2}$ ]]; then
476484
check_result $E_INVALID "invalid $object_name format :: $1"
477485
fi
478486
}

0 commit comments

Comments
 (0)