issue 57 Bad regexp prevents some other styles from applying
This commit is contained in:
parent
a3a5740ea8
commit
5623fef058
|
@ -157,6 +157,10 @@
|
||||||
"message": "Remove section",
|
"message": "Remove section",
|
||||||
"description": "Label for the button to remove a section"
|
"description": "Label for the button to remove a section"
|
||||||
},
|
},
|
||||||
|
"styleBadRegexp": {
|
||||||
|
"message": "Regexp is invalid.",
|
||||||
|
"description": "Validation message for a bad regexp in a style"
|
||||||
|
},
|
||||||
"styleCancelEditLabel": {
|
"styleCancelEditLabel": {
|
||||||
"message": "Back to manage",
|
"message": "Back to manage",
|
||||||
"description": "Label for cancel button for style editing"
|
"description": "Label for cancel button for style editing"
|
||||||
|
|
|
@ -159,7 +159,13 @@ function sectionAppliesToUrl(section, url) {
|
||||||
if (regexp[regexp.length - 1] != "$") {
|
if (regexp[regexp.length - 1] != "$") {
|
||||||
regexp += "$";
|
regexp += "$";
|
||||||
}
|
}
|
||||||
return (new RegExp(regexp)).test(url);
|
try {
|
||||||
|
var re = new RegExp(regexp);
|
||||||
|
} catch (ex) {
|
||||||
|
console.log(section.id + "'s regexp '" + regexp + "' is not valid");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return (re).test(url);
|
||||||
})) {
|
})) {
|
||||||
console.log(section.id + " applies to " + url + " due to regexp rules");
|
console.log(section.id + " applies to " + url + " due to regexp rules");
|
||||||
return true;
|
return true;
|
||||||
|
|
24
edit.js
24
edit.js
|
@ -149,6 +149,30 @@ function validate() {
|
||||||
if (name == "") {
|
if (name == "") {
|
||||||
return t("styleMissingName");
|
return t("styleMissingName");
|
||||||
}
|
}
|
||||||
|
// validate the regexps
|
||||||
|
if (Array.prototype.some.call(document.querySelectorAll(".applies-to-list"), function(list) {
|
||||||
|
return Array.prototype.some.call(list.childNodes, function(li) {
|
||||||
|
if (li.className == appliesToEverythingTemplate.className) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var valueElement = li.querySelector("[name=applies-value]");
|
||||||
|
var a = li.querySelector("[name=applies-type]").value;
|
||||||
|
var b = valueElement.value;
|
||||||
|
if (a && b) {
|
||||||
|
if (a == "regexp") {
|
||||||
|
try {
|
||||||
|
new RegExp(b);
|
||||||
|
} catch (ex) {
|
||||||
|
valueElement.focus();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
})) {
|
||||||
|
return t("styleBadRegexp");
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user