test: Add test to check hostname length

This adds a test to check the length of the hostname.
This commit is contained in:
regexowl 2024-12-12 10:14:13 +01:00 committed by Michal Gold
parent dc24ba24e4
commit 3bd4dc89c4
2 changed files with 25 additions and 10 deletions

View file

@ -92,14 +92,14 @@ export const isNtpServerValid = (ntpServer: string) => {
};
export const isHostnameValid = (hostname: string) => {
switch (true) {
case hostname.length > 63:
return false;
case hostname !== '':
return /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$/.test(
hostname
);
default:
return true;
if (!hostname) {
return true;
}
return (
hostname.length < 65 &&
/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$/.test(
hostname
)
);
};