From c3d796d04457dd0e7705907664eca35d65c78ea9 Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Mon, 18 Dec 2023 19:53:50 +0100 Subject: [PATCH] [FIX] web_editor: prevent crash if data-shape-colors is not set There is cases leading to have a `data-shape` but no `data-shape-colors`. It then makes the code crash. Step to reproduce: - Drag & drop "Text - Image" snippet - Double click on an image to replace it - Select in the media dialog "Add URL" and insert a CORS protected image URL - The image is correctly added, and its url is something like `/web/image/123-redirect/xxx.jpg` - Click on the image and then click on its "Animation" option -> It crashes In such a case, the code was crashing on the line below this fix: `img.dataset.shapeColors.split(';')` The modified code here is related to commit [1]. But the code only break in Odoo 17, probably following commit [2]. [1]: https://github.com/odoo/odoo/commit/cd403480f90cf7103651f3be818a14b06d3c73ca [2]: https://github.com/odoo/odoo/commit/7f730f81ec541cc7791fc6b3fded17c838433f85 Part-of: odoo/odoo#146732 --- addons/web_editor/static/src/js/editor/snippets.options.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js index c0b64e7d485..7a9c9f05ba9 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -7002,7 +7002,8 @@ registry.ImageTools = ImageHandlerOption.extend({ if (widgetName.startsWith('img-shape-color')) { const img = this._getImg(); const shapeName = img.dataset.shape; - if (!shapeName) { + const shapeColors = img.dataset.shapeColors; + if (!shapeName || !shapeColors) { return false; } const colors = img.dataset.shapeColors.split(';');