[FIX] im_livechat: prevent crash in rule matching if URL not set

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) <seb@odoo.com>
This commit is contained in:
Sébastien Theys
2020-02-28 15:16:17 +00:00
parent 0d73734325
commit 5e5fc53aaa
@@ -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)