From 35ff9a3d1cbd1d3a41467d2526dd41577abd2b3b Mon Sep 17 00:00:00 2001 From: Benjamin Vray Date: Tue, 31 Oct 2023 10:26:09 +0000 Subject: [PATCH] [FIX] web_editor: fix saving base64 image Some Odoo employees reported a traceback that appeared when saving a task in the Project app. It turned out that this was caused by an image having the class 'o_b64_image_to_save' even though the image was not in Base64 format. Although we couldn't reproduce the bug, we are addressing the result (the traceback) by preventing the saving of an image having the 'o_b64_image_to_save' class if the image is not in Base64. See https://github.com/odoo/odoo/commit/3bbce756c69a206d07abd31059f0392c26b36096 task-3576889 closes odoo/odoo#142571 X-original-commit: 7934aefb7d52ee20941b4583cbf0a50e28c345f6 Signed-off-by: Romain Derie (rde) --- addons/web_editor/static/src/js/wysiwyg/wysiwyg.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 3aede52d3b9..716f7db3087 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -3354,11 +3354,19 @@ export class Wysiwyg extends Component { * @param {number} resId */ async _saveB64Image(el, resModel, resId) { + el.classList.remove('o_b64_image_to_save'); + const imageData = el.getAttribute('src').split('base64,')[1]; + if (!imageData) { + // Checks if the image is in base64 format for RPC call. Relying + // only on the presence of the class "o_b64_image_to_save" is not + // robust enough. + return; + } const attachment = await this._serviceRpc( '/web_editor/attachment/add_data', { name: el.dataset.fileName || '', - data: el.getAttribute('src').split(',')[1], + data: imageData, is_image: true, res_model: resModel, res_id: resId, @@ -3385,7 +3393,6 @@ export class Wysiwyg extends Component { } el.setAttribute('src', src); } - el.classList.remove('o_b64_image_to_save'); } /** * Saves a modified image as an attachment.