]> git.wh0rd.org Git - tt-rss.git/commitdiff
check regular expression before adding/saving filter
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Thu, 11 Nov 2010 11:26:44 +0000 (14:26 +0300)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Thu, 11 Nov 2010 11:26:44 +0000 (14:26 +0300)
functions.js
modules/backend-rpc.php
prefs.js
tt-rss.js

index 9e65a6dceaac0d1ad98b8bc5581d503c70e15f75..56285b731232e200c189dce2ae5464a13cb13bb2 100644 (file)
@@ -577,55 +577,6 @@ function parse_counters(reply, scheduled_call) {
 
 } */
 
-function handle_rpc_reply(transport, scheduled_call) {
-       try {
-               if (offline_mode) return false;
-
-               if (!transport.responseText && db) {
-                       offlineConfirmModeChange();
-                       return false;
-               } 
-
-               if (transport.responseXML) {
-
-                       if (!transport_error_check(transport)) return false;
-
-                       var message = transport.responseXML.getElementsByTagName("message")[0];
-
-                       if (message) {
-                               message = message.firstChild.nodeValue;
-
-                               if (message == "UPDATE_COUNTERS") {
-                                       setInitParam("last_article_id", -1);
-                                       _force_scheduled_update = true;
-                               }
-                       }
-
-                       var counters = transport.responseXML.getElementsByTagName("counters")[0];
-       
-                       if (counters)
-                               parse_counters(counters, scheduled_call);
-
-                       var runtime_info = transport.responseXML.getElementsByTagName("runtime-info")[0];
-
-                       if (runtime_info)
-                               parse_runtime_info(runtime_info);
-
-                       if (feedsSortByUnread())
-                               resort_feedlist();
-
-                       hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
-
-               } else {
-                       notify_error("Error communicating with server.");
-               }
-
-       } catch (e) {
-               exception_error("handle_rpc_reply", e, transport);
-       }
-
-       return true;
-}
 
 function get_feed_unread(id) {
        try {
@@ -1290,20 +1241,45 @@ function createFilter() {
                        alert(__("Can't add filter: nothing to match on."));
                        return false;
                }
+
+               var query = "?op=rpc&subop=verifyRegexp&reg_exp=" + param_escape(reg_exp);
+
+               notify_progress("Verifying regular expression...");
+
+               new Ajax.Request("backend.php", {
+                               parameters: query,
+                               onComplete: function(transport) {
+                                       handle_rpc_reply(transport);
+
+                                       var response = transport.responseXML;
+
+                                       if (response) {
+                                               var s = response.getElementsByTagName("status")[0].firstChild.nodeValue;
        
-               var query = Form.serialize("filter_add_form");
-       
-               // we can be called from some other tab in Prefs                
-               if (typeof active_tab != 'undefined' && active_tab) {
-                       active_tab = "filterConfig";
-               }
-       
-               new Ajax.Request("backend.php?" + query, {
-                       onComplete: function (transport) {
-                               infobox_submit_callback2(transport);
+                                               notify('');
+
+                                               if (s == "INVALID") {
+                                                       alert("Match regular expression seems to be invalid.");
+                                                       return;
+                                               } else {
+
+                                                       var query = Form.serialize("filter_add_form");
+                                               
+                                                       // we can be called from some other tab in Prefs                
+                                                       if (typeof active_tab != 'undefined' && active_tab) {
+                                                               active_tab = "filterConfig";
+                                                       }
+                                               
+                                                       new Ajax.Request("backend.php?" + query, {
+                                                               onComplete: function (transport) {
+                                                                       infobox_submit_callback2(transport);
+                                                               } });
+                                                       
+                                                       return true;
+                                               }
+                                       }
+
                        } });
-               
-               return true;
 
        } catch (e) {
                exception_error("createFilter", e);
index 8eacb199eff43f6041c82cd4cd05761233deff35..6792fae7f8f04cf034aeb7492a5285e437e1f2a7 100644 (file)
                        return;
                }
 
+               if ($subop == "verifyRegexp") {
+                       $reg_exp = $_REQUEST["reg_exp"];
+
+                       print "<rpc-reply><status>";
+
+                       if (@preg_match("/$reg_exp/i", "TEST") === false) {
+                               print "INVALID";
+                       } else {
+                               print "OK";
+                       }
+
+                       print "</status></rpc-reply>";
+
+                       return;
+               }
+
                print "<rpc-reply><error>Unknown method: $subop</error></rpc-reply>";
        }
 ?>
index ed8d1679c037b74dac7bf1b568e49da5f6d1984c..2d8b02942e7e47ed92c9d896ee530cfbba902f2e 100644 (file)
--- a/prefs.js
+++ b/prefs.js
@@ -764,19 +764,44 @@ function userEditSave() {
 
 
 function filterEditSave() {
-
        try {
+               var reg_exp = document.forms["filter_edit_form"].reg_exp.value;
 
-               notify_progress("Saving filter...");
-       
-               var query = "?" + Form.serialize("filter_edit_form");
-       
-               closeInfoBox();
+               var query = "?op=rpc&subop=verifyRegexp&reg_exp=" + param_escape(reg_exp);
+
+               notify_progress("Verifying regular expression...");
 
                new Ajax.Request("backend.php", {
                                parameters: query,
                                onComplete: function(transport) {
-                                               filterlist_callback2(transport);
+                                       handle_rpc_reply(transport);
+
+                                       var response = transport.responseXML;
+
+                                       if (response) {
+                                               var s = response.getElementsByTagName("status")[0].firstChild.nodeValue;
+       
+                                               notify('');
+
+                                               if (s == "INVALID") {
+                                                       alert("Match regular expression seems to be invalid.");
+                                                       return;
+                                               } else {
+
+                                                       var query = "?" + Form.serialize("filter_edit_form");
+                                       
+                                                       notify_progress("Saving filter...");
+                       
+                                                       Form.disable("filter_edit_form");
+
+                                                       new Ajax.Request("backend.php", {
+                                                                       parameters: query,
+                                                                       onComplete: function(transport) {
+                                                                                       closeInfoBox();
+                                                                                       filterlist_callback2(transport);
+                                                               } });
+                                               }
+                                       }
                        } });
 
        } catch (e) {
@@ -2099,4 +2124,20 @@ function clearFeedAccessKeys() {
        return false;
 }
 
+function handle_rpc_reply(transport, scheduled_call) {
+       try {
+               if (transport.responseXML) {
+
+                       if (!transport_error_check(transport)) return false;
+
+               } else {
+                       notify_error("Error communicating with server.");
+               }
+
+       } catch (e) {
+               exception_error("handle_rpc_reply", e, transport);
+       }
+
+       return true;
+}
 
index b97a19aa1d74ea7af5275f0a61da28209904a938..e755faf70893378a52af57a1a3d1684fbcf3f965 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -1250,3 +1250,53 @@ function showFeedsWithErrors() {
        displayDlg('feedUpdateErrors');
 }
 
+function handle_rpc_reply(transport, scheduled_call) {
+       try {
+               if (offline_mode) return false;
+
+               if (!transport.responseText && db) {
+                       offlineConfirmModeChange();
+                       return false;
+               } 
+
+               if (transport.responseXML) {
+
+                       if (!transport_error_check(transport)) return false;
+
+                       var message = transport.responseXML.getElementsByTagName("message")[0];
+
+                       if (message) {
+                               message = message.firstChild.nodeValue;
+
+                               if (message == "UPDATE_COUNTERS") {
+                                       setInitParam("last_article_id", -1);
+                                       _force_scheduled_update = true;
+                               }
+                       }
+
+                       var counters = transport.responseXML.getElementsByTagName("counters")[0];
+       
+                       if (counters)
+                               parse_counters(counters, scheduled_call);
+
+                       var runtime_info = transport.responseXML.getElementsByTagName("runtime-info")[0];
+
+                       if (runtime_info)
+                               parse_runtime_info(runtime_info);
+
+                       if (feedsSortByUnread())
+                               resort_feedlist();
+
+                       hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
+
+               } else {
+                       notify_error("Error communicating with server.");
+               }
+
+       } catch (e) {
+               exception_error("handle_rpc_reply", e, transport);
+       }
+
+       return true;
+}
+