Url validation on thumbnails suggested

This commit is contained in:
Kasper Rynning-Tønnesen
2018-05-02 15:31:59 +02:00
parent a66eb49b2b
commit 93fc30dada
2 changed files with 20 additions and 2 deletions

View File

@@ -1,5 +1,23 @@
function isUrl(str) {
var pattern = new RegExp("\\b(((ht|f)tp(s?)\\:\\/\\/|~\\/|\\/)|www.)" +
"(\\w+:\\w+@)?(([-\\w]+\\.)+(com|org|net|gov" +
"|mil|biz|info|mobi|name|aero|jobs|museum" +
"|travel|[a-z]{2}))(:[\\d]{1,5})?" +
"(((\\/([-\\w~!$+|.,=]|%[a-f\\d]{2})+)+|\\/)+|\\?|#)?" +
"((\\?([-\\w~!$+|.,*:]|%[a-f\\d{2}])+=?" +
"([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)" +
"(&(?:[-\\w~!$+|.,*:]|%[a-f\\d{2}])+=?" +
"([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)*)*" +
"(#([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)?\\b");
if(!pattern.test(str)) {
return false;
} else {
return true;
}
}
function thumbnail(msg, coll, guid, offline, socket) { function thumbnail(msg, coll, guid, offline, socket) {
if(msg.thumbnail != undefined && msg.channel && msg.channel != undefined){ if(msg.thumbnail != undefined && msg.channel && msg.channel != undefined && isUrl(msg.thumbnail)){
if(typeof(msg.channel) != "string" || typeof(msg.thumbnail) != "string") if(typeof(msg.channel) != "string" || typeof(msg.thumbnail) != "string")
{ {
var result = { var result = {

View File

@@ -708,7 +708,7 @@ function toast(msg) {
break; break;
case "thumbnail_denied": case "thumbnail_denied":
if(embed) return; if(embed) return;
msg = "The thumbnail will be denied"; msg = "The thumbnail is not an url..";
break; break;
case "description_denied": case "description_denied":
if(embed) return; if(embed) return;