This is an automated email from the ASF dual-hosted git repository. sebb pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-ponymail.git
The following commit(s) were added to refs/heads/master by this push: new 71bca89 Simplify address validation 71bca89 is described below commit 71bca896da6213471262fe587bb26358f6c300ed Author: Sebb <s...@apache.org> AuthorDate: Tue Mar 5 22:26:53 2019 +0000 Simplify address validation --- site/js/dev/ponymail_assign_vars.js | 1 - site/js/dev/ponymail_helperfuncs.js | 10 +++++----- site/js/dev/ponymail_pagebuilder.js | 8 +++----- site/js/dev/ponymail_trends.js | 5 ++--- site/js/ponymail.js | 24 ++++++++++-------------- 5 files changed, 20 insertions(+), 28 deletions(-) diff --git a/site/js/dev/ponymail_assign_vars.js b/site/js/dev/ponymail_assign_vars.js index 1d03dcc..ef2df5e 100644 --- a/site/js/dev/ponymail_assign_vars.js +++ b/site/js/dev/ponymail_assign_vars.js @@ -60,7 +60,6 @@ var pending_urls = {} // URL list for GetAsync's support functions (such as the var pb_refresh = 0 var treeview_guard = {} var mbox_month = null -var INVALID_MAGIC_MARKER = "$INVALID" var URL_BASE = pm_config.URLBase ? pm_config.URLBase.replace(/\/+/g, "/") : "" diff --git a/site/js/dev/ponymail_helperfuncs.js b/site/js/dev/ponymail_helperfuncs.js index 7f38d44..d9514ec 100644 --- a/site/js/dev/ponymail_helperfuncs.js +++ b/site/js/dev/ponymail_helperfuncs.js @@ -175,11 +175,11 @@ function isArray(obj) { return (obj && obj.constructor && obj.constructor == Array) } - -// ML address: only accept valid mailing list IDs -function validate_address(val) { - var m = val.match(/^[-@A-Za-z.0-9]+$/); - return m ? m[0] : INVALID_MAGIC_STRING; +// ML address: only accept valid mailing list name, domain or both +// return true if the address is valid +function valid_address(val) { + return val.match(/^[-@A-Za-z.0-9]+$/); } + // Check for slow URLs every 0.1 seconds window.setInterval(checkForSlows, 100) diff --git a/site/js/dev/ponymail_pagebuilder.js b/site/js/dev/ponymail_pagebuilder.js index 9a1d4bb..8619aeb 100644 --- a/site/js/dev/ponymail_pagebuilder.js +++ b/site/js/dev/ponymail_pagebuilder.js @@ -393,15 +393,13 @@ function getListInfo(list, xdomain, nopush) { xdomain = list.replace(/^.*?@/, "") } - if (list) list = validate_address(list); - if (xdomain) xdomain = validate_address(xdomain); - // If invalid address passed, complain and exit - no need to attempt fetching stats - if (list == INVALID_MAGIC_STRING || xdomain == INVALID_MAGIC_STRING) { + // N.B. Only check list and xdomain if they are defined + if ((list && ! valid_address(list)) || (xdomain && ! valid_address(xdomain))) { alert("Invalid mailing list address supplied!"); return } - + // Sort lists by usage before we enter here... var listnames = [] if (all_lists[xdomain]) { diff --git a/site/js/dev/ponymail_trends.js b/site/js/dev/ponymail_trends.js index 7de7668..69f9e7a 100644 --- a/site/js/dev/ponymail_trends.js +++ b/site/js/dev/ponymail_trends.js @@ -287,12 +287,11 @@ function gatherTrends() { var dspan = a_arr[1] var query = a_arr[2] - list = validate_address(list); - if (list == INVALID_MAGIC_STRING) { + if (!valid_address(list)) { alert("Invalid mailing list address supplied!"); return } - + // Try to detect header searches, if present var nquery = "" if (query && query.length > 0) { diff --git a/site/js/ponymail.js b/site/js/ponymail.js index 701be87..80325d0 100644 --- a/site/js/ponymail.js +++ b/site/js/ponymail.js @@ -68,7 +68,6 @@ var pending_urls = {} // URL list for GetAsync's support functions (such as the var pb_refresh = 0 var treeview_guard = {} var mbox_month = null -var INVALID_MAGIC_MARKER = "$INVALID" var URL_BASE = pm_config.URLBase ? pm_config.URLBase.replace(/\/+/g, "/") : "" @@ -2321,12 +2320,12 @@ function isArray(obj) { return (obj && obj.constructor && obj.constructor == Array) } - -// ML address: only accept valid mailing list IDs -function validate_address(val) { - var m = val.match(/^[-@A-Za-z.0-9]+$/); - return m ? m[0] : INVALID_MAGIC_STRING; +// ML address: only accept valid mailing list name, domain or both +// return true if the address is valid +function valid_address(val) { + return val.match(/^[-@A-Za-z.0-9]+$/); } + // Check for slow URLs every 0.1 seconds window.setInterval(checkForSlows, 100) @@ -4045,15 +4044,13 @@ function getListInfo(list, xdomain, nopush) { xdomain = list.replace(/^.*?@/, "") } - if (list) list = validate_address(list); - if (xdomain) xdomain = validate_address(xdomain); - // If invalid address passed, complain and exit - no need to attempt fetching stats - if (list == INVALID_MAGIC_STRING || xdomain == INVALID_MAGIC_STRING) { + // N.B. Only check list and xdomain if they are defined + if ((list && ! valid_address(list)) || (xdomain && ! valid_address(xdomain))) { alert("Invalid mailing list address supplied!"); return } - + // Sort lists by usage before we enter here... var listnames = [] if (all_lists[xdomain]) { @@ -5091,12 +5088,11 @@ function gatherTrends() { var dspan = a_arr[1] var query = a_arr[2] - list = validate_address(list); - if (list == INVALID_MAGIC_STRING) { + if (!valid_address(list)) { alert("Invalid mailing list address supplied!"); return } - + // Try to detect header searches, if present var nquery = "" if (query && query.length > 0) {