properly handle invalid regular expressions supplied when testing filters, add some additional regexp checks (closes #427)
This commit is contained in:
parent
7b8ff151ed
commit
56fbb82cb0
4 changed files with 136 additions and 95 deletions
|
@ -33,6 +33,16 @@ class Pref_Filters extends Protected_Handler {
|
|||
else
|
||||
$feed = -4;
|
||||
|
||||
$regexp_valid = preg_match('/' . $filter['reg_exp'] . '/',
|
||||
$filter['reg_exp']) !== FALSE;
|
||||
|
||||
print __("Articles matching this filter:");
|
||||
|
||||
print "<div class=\"inactiveFeedHolder\">";
|
||||
print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">";
|
||||
|
||||
if ($regexp_valid) {
|
||||
|
||||
$feed_title = getFeedTitle($this->link, $feed);
|
||||
|
||||
$qfh_ret = queryFeedHeadlines($this->link, $cat_filter ? $cat_id : $feed,
|
||||
|
@ -44,11 +54,6 @@ class Pref_Filters extends Protected_Handler {
|
|||
$articles = array();
|
||||
$found = 0;
|
||||
|
||||
print __("Articles matching this filter:");
|
||||
|
||||
print "<div class=\"inactiveFeedHolder\">";
|
||||
print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">";
|
||||
|
||||
while ($line = db_fetch_assoc($result)) {
|
||||
|
||||
$entry_timestamp = strtotime($line["updated"]);
|
||||
|
@ -83,6 +88,11 @@ class Pref_Filters extends Protected_Handler {
|
|||
print "<tr><td align='center'>" .
|
||||
__("No articles matching this filter has been found.") . "</td></tr>";
|
||||
}
|
||||
} else {
|
||||
print "<tr><td align='center' class='error'>" .
|
||||
__("Invalid regular expression.") . "</td></tr>";
|
||||
|
||||
}
|
||||
|
||||
print "</table>";
|
||||
print "</div>";
|
||||
|
|
|
@ -4973,6 +4973,11 @@
|
|||
function filter_to_sql($filter) {
|
||||
$query = "";
|
||||
|
||||
$regexp_valid = preg_match('/' . $filter['reg_exp'] . '/',
|
||||
$filter['reg_exp']) !== FALSE;
|
||||
|
||||
if ($regexp_valid) {
|
||||
|
||||
if (DB_TYPE == "pgsql")
|
||||
$reg_qpart = "~";
|
||||
else
|
||||
|
@ -5028,8 +5033,10 @@
|
|||
$query .= " AND ";
|
||||
}
|
||||
|
||||
|
||||
return $query;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Status codes:
|
||||
|
|
|
@ -982,6 +982,24 @@ function quickAddFilter() {
|
|||
test: function() {
|
||||
if (this.validate()) {
|
||||
|
||||
var query = "?op=rpc&method=verifyRegexp®_exp=" +
|
||||
param_escape(dialog.attr('value').reg_exp);
|
||||
|
||||
notify_progress("Verifying regular expression...");
|
||||
|
||||
new Ajax.Request("backend.php", {
|
||||
parameters: query,
|
||||
onComplete: function(transport) {
|
||||
var reply = JSON.parse(transport.responseText);
|
||||
|
||||
if (reply) {
|
||||
notify('');
|
||||
|
||||
if (!reply['status']) {
|
||||
alert("Invalid regular expression.");
|
||||
return;
|
||||
} else {
|
||||
|
||||
if (dijit.byId("filterTestDlg"))
|
||||
dijit.byId("filterTestDlg").destroyRecursive();
|
||||
|
||||
|
@ -994,7 +1012,9 @@ function quickAddFilter() {
|
|||
});
|
||||
|
||||
tdialog.show();
|
||||
|
||||
}
|
||||
}
|
||||
}});
|
||||
}
|
||||
},
|
||||
execute: function() {
|
||||
|
@ -1014,7 +1034,7 @@ function quickAddFilter() {
|
|||
notify('');
|
||||
|
||||
if (!reply['status']) {
|
||||
alert("Match regular expression seems to be invalid.");
|
||||
alert("Invalid regular expression.");
|
||||
return;
|
||||
} else {
|
||||
notify_progress("Saving data...", true);
|
||||
|
|
|
@ -1407,3 +1407,7 @@ a.bookmarklet {
|
|||
padding : 1em;
|
||||
color : gray;
|
||||
}
|
||||
|
||||
td.error {
|
||||
color : red;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue