From df2a28c86f31c30b9a97095f8475414eb97c2820 Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Tue, 20 Sep 2016 17:42:39 +0200 Subject: [PATCH] [FIX] website_forum: valid url at submit. Older regexp was not working, event with the sample: https://www.odoo.com Should be shared in util.js --- .../static/src/js/website_forum.js | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/addons/website_forum/static/src/js/website_forum.js b/addons/website_forum/static/src/js/website_forum.js index e08e75f0d33..4b4d704e633 100644 --- a/addons/website_forum/static/src/js/website_forum.js +++ b/addons/website_forum/static/src/js/website_forum.js @@ -235,7 +235,45 @@ if(!$('.website_forum').length) { if (url.search("^http(s?)://.*")) { url = 'http://'+url; } - var regex = new RegExp("(http(s)?://.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)"); + + // https://gist.github.com/dperini/729294 + var regex = new RegExp( + "^" + + // protocol identifier + "(?:(?:https?|ftp)://)" + + // user:pass authentication + "(?:\\S+(?::\\S*)?@)?" + + "(?:" + + // IP address exclusion + // private & local networks + "(?!(?:10|127)(?:\\.\\d{1,3}){3})" + + "(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" + + "(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})" + + // IP address dotted notation octets + // excludes loopback network 0.0.0.0 + // excludes reserved space >= 224.0.0.0 + // excludes network & broacast addresses + // (first & last IP address of each class) + "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" + + "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" + + "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" + + "|" + + // host name + "(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)" + + // domain name + "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*" + + // TLD identifier + "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" + + // TLD may end with dot + "\\.?" + + ")" + + // port number + "(?::\\d{2,5})?" + + // resource path + "(?:[/?#]\\S*)?" + + "$", "i" + ); + if(regex.test(url)){ ajax.jsonRpc("/forum/get_url_title", 'call', {'url': url}).then(function (data) { if (data) {