From 5e5fc53aaa0e5af144c8c7069ff4e20f950a20fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Fri, 28 Feb 2020 10:43:24 +0000 Subject: [PATCH] [FIX] im_livechat: prevent crash in rule matching if URL not set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The URL might not be set because it comes from `referer`, in that case match the first rule with no `regex_url`. It crashes before this commit because `re.search()` is expecting a string and `headers.get()` is defaulting to `None`. opw-2205202 closes odoo/odoo#46593 X-original-commit: e2f8caf07b2f749935df9184ded738cc1c482423 Signed-off-by: Sébastien Theys (seb) --- addons/im_livechat/models/im_livechat_channel.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/im_livechat/models/im_livechat_channel.py b/addons/im_livechat/models/im_livechat_channel.py index 8ccd3f99063..c9217504cdd 100644 --- a/addons/im_livechat/models/im_livechat_channel.py +++ b/addons/im_livechat/models/im_livechat_channel.py @@ -270,7 +270,9 @@ class ImLivechatChannelRule(models.Model): """ def _match(rules): for rule in rules: - if re.search(rule.regex_url or '', url): + # url might not be set because it comes from referer, in that + # case match the first rule with no regex_url + if re.search(rule.regex_url or '', url or ''): return rule return False # first, search the country specific rules (the first match is returned)