test: Add test to check hostname length
This adds a test to check the length of the hostname.
This commit is contained in:
parent
dc24ba24e4
commit
3bd4dc89c4
2 changed files with 25 additions and 10 deletions
|
|
@ -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
|
||||
)
|
||||
);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue