From 85cb19b294b8e73dfd612e8735ec088517a42d97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Phil=C3=A9mon=20van=20Helden?= Date: Wed, 18 Aug 2021 12:22:43 +0000 Subject: [PATCH] [IMP] web_editor, base: allow parameters in image URLs When adding an image to the library from an URL, if the URL contains parameters (e.g. ?width=200&height=200), the link will not be accepted. In this commit, we remove these parameters from the URL before checking the image, so that the URL is considered valid. We also remove these parameters before computing the mimetype of the image, since it is computed based on the end part of the URL. task-2618494 Part-of: odoo/odoo#75205 --- addons/web_editor/static/src/js/wysiwyg/widgets/media.js | 2 +- odoo/addons/base/models/ir_attachment.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/media.js b/addons/web_editor/static/src/js/wysiwyg/widgets/media.js index 38db3565971..aa4467a5ee4 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/media.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/media.js @@ -658,7 +658,7 @@ var FileWidget = SearchableMediaWidget.extend({ * @private */ _onURLInputChange: function () { - var inputValue = this.$urlInput.val(); + const inputValue = this.$urlInput.val().split('?')[0]; var emptyValue = (inputValue === ''); var isURL = /^.+\..+$/.test(inputValue); // TODO improve diff --git a/odoo/addons/base/models/ir_attachment.py b/odoo/addons/base/models/ir_attachment.py index f87da94153d..4feb3e43f0a 100644 --- a/odoo/addons/base/models/ir_attachment.py +++ b/odoo/addons/base/models/ir_attachment.py @@ -283,7 +283,7 @@ class IrAttachment(models.Model): if not mimetype and values.get('name'): mimetype = mimetypes.guess_type(values['name'])[0] if not mimetype and values.get('url'): - mimetype = mimetypes.guess_type(values['url'])[0] + mimetype = mimetypes.guess_type(values['url'].split('?')[0])[0] if not mimetype or mimetype == 'application/octet-stream': raw = None if values.get('raw'):