Add warning as discussed in #347

This commit is contained in:
calzoneman 2014-04-13 02:14:34 -05:00
parent cfe34112a4
commit 64980bc293
2 changed files with 33 additions and 0 deletions

View file

@ -582,6 +582,13 @@ $("#cs-chatfilters-newsubmit").click(function () {
var regex = $("#cs-chatfilters-newregex").val(); var regex = $("#cs-chatfilters-newregex").val();
var flags = $("#cs-chatfilters-newflags").val(); var flags = $("#cs-chatfilters-newflags").val();
var replace = $("#cs-chatfilters-newreplace").val(); var replace = $("#cs-chatfilters-newreplace").val();
var entcheck = checkEntitiesInStr(regex);
if (entcheck) {
alert("Warning: " + entcheck.src + " will be replaced by " +
entcheck.replace + " in the message preprocessor. This " +
"regular expression may not match what you intended it to " +
"match.");
}
try { try {
new RegExp(regex, flags); new RegExp(regex, flags);

View file

@ -2127,6 +2127,25 @@ function formatCSBanlist() {
}); });
} }
function checkEntitiesInStr(str) {
var entities = {
"&": "&",
"<": "&lt;",
">": "&gt;",
'"': "&quot;",
"'": "&#39;",
"(": "&#40;",
")": "&#41;"
};
var m = str.match(/([&<>"'\(\)])/);
if (m && m[1] in entities) {
return { src: m[1], replace: entities[m[1]] };
} else {
return false;
}
}
function formatCSChatFilterList() { function formatCSChatFilterList() {
var tbl = $("#cs-chatfilters table"); var tbl = $("#cs-chatfilters table");
tbl.find("tbody").remove(); tbl.find("tbody").remove();
@ -2204,6 +2223,13 @@ function formatCSChatFilterList() {
$("<span/>").addClass("glyphicon glyphicon-floppy-save").appendTo(save); $("<span/>").addClass("glyphicon glyphicon-floppy-save").appendTo(save);
save.click(function () { save.click(function () {
f.source = regex.val(); f.source = regex.val();
var entcheck = checkEntitiesInStr(f.source);
if (entcheck) {
alert("Warning: " + entcheck.src + " will be replaced by " +
entcheck.replace + " in the message preprocessor. This " +
"regular expression may not match what you intended it to " +
"match.");
}
f.flags = flags.val(); f.flags = flags.val();
f.replace = replace.val(); f.replace = replace.val();
f.filterlinks = filterlinks.prop("checked"); f.filterlinks = filterlinks.prop("checked");