🐛 Better URL validation, Fixed #471

This commit is contained in:
Liyas Thomas
2020-01-03 21:07:41 +05:30
parent 35df7c6429
commit 0930b1ada8

View File

@@ -209,28 +209,28 @@ export default {
}, },
computed: { computed: {
urlValid() { urlValid() {
const pattern = new RegExp( const protocol = "^(wss?:\\/\\/)?";
"^(wss?:\\/\\/)?" + const validIP = new RegExp(
"((([a-z\\d]([a-z\\d-]*[a-z:@\\d])*)\\.)+[a-z]{2,}|" + protocol +
"((\\d{1,3}\\.){3}\\d{1,3}))" + "(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
"(\\:\\d+)?(\\/[-a-z\\d%_.~+@]*)*" +
"(\\?[:\\;&a-z\\d%_.~+=-]*)?" +
"(\\#[-a-z\\d_]*)?$",
"i"
); );
return pattern.test(this.url); const validHostname = new RegExp(
protocol +
"(([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/])$"
);
return validIP.test(this.url) || validHostname.test(this.url);
}, },
serverValid() { serverValid() {
const pattern = new RegExp( const protocol = "^(https?:\\/\\/)?";
"^(http(s)?:\\/\\/)?" + const validIP = new RegExp(
"((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|" + protocol +
"((\\d{1,3}\\.){3}\\d{1,3}))" + "(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
"(\\:\\d+)?(\\/[-a-z\\d%_.~+@]*)*" +
"(\\?[:\\;&a-z\\d%_.~+=-]*)?" +
"(\\#[-a-z\\d_]*)?$",
"i"
); );
return pattern.test(this.server); const validHostname = new RegExp(
protocol +
"(([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/])$"
);
return validIP.test(this.server) || validHostname.test(this.server);
} }
}, },
methods: { methods: {