From 135aacd33c444adcbd7d9ae7d21bf5b197c6d97f Mon Sep 17 00:00:00 2001 From: Benoit Socias Date: Mon, 9 May 2022 14:37:03 +0000 Subject: [PATCH] [FIX] web_editor: not fail when clicking on a technical SVG Since [1] when the stars were made available in the power box, an exception is raised when clicking on a technical SVG of the "Steps" block. This happens because SVGs have their `nodeType === Node.ELEMENT_NODE`, they have `className` and `classList` properties, but their `className` is not a string: it is an `SVGAnimatedString`. Because of this, the `includes` method is not available on `className`. This commit prevents the non-existing `includes` from being called. Steps to reproduce: - Drop a "Steps" block into the page. - Click on the column before the first step, at the same height as the steps icons. (There is an hidden SVG there containing the definition of the arrows head.) => Did raise an exception. [1]: https://github.com/odoo/odoo/commit/8266b978e1bfa5bedfaf1c4fcceadd26400fc85c task-2845963 X-original-commit: dbfbf264750a0760d4f2d96a1b7a13ea27472316 Part-of: odoo/odoo#96071 --- .../src/js/editor/odoo-editor/src/OdooEditor.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js index 0673197c9dc..2791ebf7b72 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js @@ -3004,14 +3004,13 @@ export class OdooEditor extends EventTarget { } // handle stars - if (node.nodeType === Node.ELEMENT_NODE && node.className.includes('fa-star') && + const isStar = el => el.nodeType === Node.ELEMENT_NODE && ( + el.classList.contains('fa-star') || el.classList.contains('fa-star-o') + ); + if (isStar(node) && node.parentElement && node.parentElement.className.includes('o_stars')) { - const previousStars = getAdjacentPreviousSiblings(node, sib => ( - sib.nodeType === Node.ELEMENT_NODE && sib.className.includes('fa-star') - )); - const nextStars = getAdjacentNextSiblings(node, sib => ( - sib.nodeType === Node.ELEMENT_NODE && sib.className.includes('fa-star') - )); + const previousStars = getAdjacentPreviousSiblings(node, isStar); + const nextStars = getAdjacentNextSiblings(node, isStar); if (nextStars.length || previousStars.length) { const shouldToggleOff = node.classList.contains('fa-star') && (!nextStars[0] || !nextStars[0].classList.contains('fa-star'));