properly handle invalid regular expressions supplied when testing filters, add some additional regexp checks (closes #427)

This commit is contained in:
Andrew Dolgov 2012-02-21 12:36:29 +04:00
parent 7b8ff151ed
commit 56fbb82cb0
4 changed files with 136 additions and 95 deletions

View File

@ -33,6 +33,16 @@ class Pref_Filters extends Protected_Handler {
else else
$feed = -4; $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); $feed_title = getFeedTitle($this->link, $feed);
$qfh_ret = queryFeedHeadlines($this->link, $cat_filter ? $cat_id : $feed, $qfh_ret = queryFeedHeadlines($this->link, $cat_filter ? $cat_id : $feed,
@ -44,11 +54,6 @@ class Pref_Filters extends Protected_Handler {
$articles = array(); $articles = array();
$found = 0; $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)) { while ($line = db_fetch_assoc($result)) {
$entry_timestamp = strtotime($line["updated"]); $entry_timestamp = strtotime($line["updated"]);
@ -83,6 +88,11 @@ class Pref_Filters extends Protected_Handler {
print "<tr><td align='center'>" . print "<tr><td align='center'>" .
__("No articles matching this filter has been found.") . "</td></tr>"; __("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 "</table>";
print "</div>"; print "</div>";

View File

@ -4973,6 +4973,11 @@
function filter_to_sql($filter) { function filter_to_sql($filter) {
$query = ""; $query = "";
$regexp_valid = preg_match('/' . $filter['reg_exp'] . '/',
$filter['reg_exp']) !== FALSE;
if ($regexp_valid) {
if (DB_TYPE == "pgsql") if (DB_TYPE == "pgsql")
$reg_qpart = "~"; $reg_qpart = "~";
else else
@ -5028,8 +5033,10 @@
$query .= " AND "; $query .= " AND ";
} }
return $query; return $query;
} else {
return false;
}
} }
// Status codes: // Status codes:

View File

@ -982,6 +982,24 @@ function quickAddFilter() {
test: function() { test: function() {
if (this.validate()) { if (this.validate()) {
var query = "?op=rpc&method=verifyRegexp&reg_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")) if (dijit.byId("filterTestDlg"))
dijit.byId("filterTestDlg").destroyRecursive(); dijit.byId("filterTestDlg").destroyRecursive();
@ -994,7 +1012,9 @@ function quickAddFilter() {
}); });
tdialog.show(); tdialog.show();
}
}
}});
} }
}, },
execute: function() { execute: function() {
@ -1014,7 +1034,7 @@ function quickAddFilter() {
notify(''); notify('');
if (!reply['status']) { if (!reply['status']) {
alert("Match regular expression seems to be invalid."); alert("Invalid regular expression.");
return; return;
} else { } else {
notify_progress("Saving data...", true); notify_progress("Saving data...", true);

View File

@ -1407,3 +1407,7 @@ a.bookmarklet {
padding : 1em; padding : 1em;
color : gray; color : gray;
} }
td.error {
color : red;
}