diff --git a/addons/website/models/ir_qweb.py b/addons/website/models/ir_qweb.py index c2386d9466c..0f73bc469f5 100644 --- a/addons/website/models/ir_qweb.py +++ b/addons/website/models/ir_qweb.py @@ -1,11 +1,15 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +import re from collections import OrderedDict from odoo import models from odoo.http import request +re_background_image = re.compile(r"(background-image\s*:\s*url\(\s*['\"]?\s*)([^)'\"]+)") + + class QWeb(models.AbstractModel): """ QWeb object for rendering stuff in the website context """ @@ -40,5 +44,8 @@ class QWeb(models.AbstractModel): if name and name in atts: atts = OrderedDict(atts) atts[name] = website.get_cdn_url(atts[name]) + if isinstance(atts.get('style'), str) and 'background-image' in atts['style']: + atts = OrderedDict(atts) + atts['style'] = re_background_image.sub(lambda m: '%s%s' % (m.group(1), website.get_cdn_url(m.group(2))), atts['style']) return atts