From ad7c0d8ea4fb696798da3a9e1fa4c37f3270bf0f Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Tue, 22 Mar 2022 15:12:55 +0000 Subject: [PATCH] [FIX] web_editor: prevent traceback on remove highlight color This prevents a traceback when no closest block to the root node can be found in the sanitizer. task-2796371 closes odoo/odoo#87187 X-original-commit: 2104f33985472cd59f067d2f1403518a332fac6d Signed-off-by: David Monjoie (dmo) --- .../lib/odoo-editor/src/utils/sanitize.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/addons/web_editor/static/lib/odoo-editor/src/utils/sanitize.js b/addons/web_editor/static/lib/odoo-editor/src/utils/sanitize.js index 4c66f2349a4..a62736f196e 100644 --- a/addons/web_editor/static/lib/odoo-editor/src/utils/sanitize.js +++ b/addons/web_editor/static/lib/odoo-editor/src/utils/sanitize.js @@ -78,15 +78,20 @@ export function areSimilarElements(node, node2) { class Sanitize { constructor(root) { this.root = root; - // Remove unique ids from checklists and stars. These will be renewed - // afterwards. - for (const node of closestBlock(root).querySelectorAll('[id^=checkId-]')) { - node.removeAttribute('id'); + const rootClosestBlock = closestBlock(root); + if (rootClosestBlock) { + // Remove unique ids from checklists and stars. These will be + // renewed afterwards. + for (const node of rootClosestBlock.querySelectorAll('[id^=checkId-]')) { + node.removeAttribute('id'); + } } this.parse(root); - // Ensure unique ids on checklists and stars. - for (const node of closestBlock(root).querySelectorAll('.o_checklist > li, .o_stars')) { - node.setAttribute('id', `checkId-${Math.floor(new Date() * Math.random())}`); + if (rootClosestBlock) { + // Ensure unique ids on checklists and stars. + for (const node of rootClosestBlock.querySelectorAll('.o_checklist > li, .o_stars')) { + node.setAttribute('id', `checkId-${Math.floor(new Date() * Math.random())}`); + } } }