Relax monitor URL validation
This commit is contained in:
1 parent
200a933647
commit
066df2c64f
1 file changed
+11
-18
@@ -128,26 +128,21 @@ const monitorValidation = joi.object({
|
|||||||
.string()
|
.string()
|
||||||
.trim()
|
.trim()
|
||||||
.custom((value, helpers) => {
|
.custom((value, helpers) => {
|
||||||
// Regex from https://gist.github.com/dperini/729294
|
const noProtocol = value.replace(/^(https?:\/\/)/, "");
|
||||||
|
|
||||||
|
if (/^[a-zA-Z0-9-]+(:\d{1,5})?$/.test(noProtocol)) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Accept full domain/IP/URL (as fallback)
|
||||||
var urlRegex = new RegExp(
|
var urlRegex = new RegExp(
|
||||||
"^" +
|
"^" +
|
||||||
// protocol identifier (optional)
|
|
||||||
// short syntax // still required
|
|
||||||
"(?:(?:https?|ftp):\\/\\/)?" +
|
"(?:(?:https?|ftp):\\/\\/)?" +
|
||||||
// user:pass BasicAuth (optional)
|
|
||||||
"(?:" +
|
"(?:" +
|
||||||
// IP address dotted notation octets
|
|
||||||
// excludes loopback network 0.0.0.0
|
|
||||||
// excludes reserved space >= 224.0.0.0
|
|
||||||
// excludes network & broadcast addresses
|
|
||||||
// (first & last IP address of each class)
|
|
||||||
"(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
|
"(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
|
||||||
"(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
|
"(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
|
||||||
"(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
|
"(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
|
||||||
"|" +
|
"|" +
|
||||||
// host & domain names, may end with dot
|
|
||||||
// can be replaced by a shortest alternative
|
|
||||||
// (?![-_])(?:[-\\w\\u00a1-\\uffff]{0,63}[^-_]\\.)+
|
|
||||||
"(?:" +
|
"(?:" +
|
||||||
"(?:" +
|
"(?:" +
|
||||||
"[a-z0-9\\u00a1-\\uffff]" +
|
"[a-z0-9\\u00a1-\\uffff]" +
|
||||||
@@ -155,21 +150,19 @@ const monitorValidation = joi.object({
|
|||||||
")?" +
|
")?" +
|
||||||
"[a-z0-9\\u00a1-\\uffff]\\." +
|
"[a-z0-9\\u00a1-\\uffff]\\." +
|
||||||
")+" +
|
")+" +
|
||||||
// TLD identifier name, may end with dot
|
|
||||||
"(?:[a-z\\u00a1-\\uffff]{2,}\\.?)" +
|
"(?:[a-z\\u00a1-\\uffff]{2,}\\.?)" +
|
||||||
")" +
|
")" +
|
||||||
// port number (optional)
|
|
||||||
"(?::\\d{2,5})?" +
|
"(?::\\d{2,5})?" +
|
||||||
// resource path (optional)
|
|
||||||
"(?:[/?#]\\S*)?" +
|
"(?:[/?#]\\S*)?" +
|
||||||
"$",
|
"$",
|
||||||
"i"
|
"i"
|
||||||
);
|
);
|
||||||
if (!urlRegex.test(value)) {
|
|
||||||
return helpers.error("string.invalidUrl");
|
if (urlRegex.test(value)) {
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return helpers.error("string.invalidUrl");
|
||||||
})
|
})
|
||||||
.messages({
|
.messages({
|
||||||
"string.empty": "This field is required.",
|
"string.empty": "This field is required.",
|
||||||
|
|||||||
Reference in new issue
Block a user