issue 57 Bad regexp prevents some other styles from applying

This commit is contained in:
Jason Barnabe 2012-11-02 22:25:04 -05:00
parent a3a5740ea8
commit 5623fef058
3 changed files with 36 additions and 2 deletions

View File

@ -157,6 +157,10 @@
"message": "Remove 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": {
"message": "Back to manage",
"description": "Label for cancel button for style editing"
@ -223,4 +227,4 @@
"message": "Update completed.",
"description": "Text that displays when an update completed"
}
}
}

View File

@ -159,7 +159,13 @@ function sectionAppliesToUrl(section, url) {
if (regexp[regexp.length - 1] != "$") {
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");
return true;

24
edit.js
View File

@ -149,6 +149,30 @@ function validate() {
if (name == "") {
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;
}