[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) <rde@odoo.com>
This commit is contained in:
Benjamin Vray
2023-11-20 03:46:49 +00:00
committed by Romain Derie
parent 6045061f81
commit 35ff9a3d1c
@@ -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.