Use URL regex to validate the blacklist URL

This commit is contained in:
Nicolo Maio 2024-04-23 10:33:09 +02:00
parent b5ec0c0a7f
commit 38e4769644
2 changed files with 16 additions and 2 deletions

View file

@ -12,6 +12,7 @@ const regexes = {
port_range_regex: String.raw`^(\d{1,5})-(\d{1,5})$`,
host_name: String.raw`^(?!\s*$)[a-zA-Z0-9._: \-\/]{1,250}|^[a-zA-Z0-9._: \-\/]{1,250}@[0-9]{0,5}`,
singleword: String.raw`^(?=[a-zA-Z0-9._:\-]{3,253}$)(?!.*[_.:\-]{2})[^_.:\-].*[^_.:\-]$`,
url: String.raw`^(https?\:\/\/[^\/\s]+(\/.*)?)$`,
}
/* ****************************************************** */
@ -56,6 +57,12 @@ const validateSingleWord = (word) => {
return singelWordRegex.test(word);
}
const validateURL = (url) => {
const urlRegex = new RegExp(regexes.url)
return urlRegex.test(url);
}
/* ****************************************************** */
const validatePortRange = (ports) => {
@ -119,6 +126,7 @@ const regexValidation = function () {
validateCommaSeparatedPortList,
validatePortRange,
validateSingleWord,
validateURL
};
}();