From 2ab529ed29c9dab05416dbb34857ec8fdadbe72b Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Fri, 18 Aug 2023 13:23:23 +0000 Subject: [PATCH] [FIX] web_editor: prevent error on undefined closest Node Summary: page with 2 popups (newsletter popup and regular popup), cookie bar all justaposed. Chatbot window also open. For some reason closestBlock(testedNode) is undefined (testedNode) is a #text Node. Change already in place for 16.3 Cause: no preventive measure for null value before creating a node iterator on the value.Node in dom does not have an ancestor of type block. Solution: backport solution from 16.3, return false when currentNodeParentBlock is null, since preceding and following would also be undefined, return false. opw-3395673 closes odoo/odoo#132590 X-original-commit: 8a72f669813bc7d8aa9038d75e08ecef00b70e01 Signed-off-by: David Monjoie (dmo) Co-authored-by: Pedro Manuel Calheiros Lima de Sousa --- .../static/src/js/editor/odoo-editor/test/spec/utils.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/utils.test.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/utils.test.js index d43e73464c7..6e22d6d2d74 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/utils.test.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/utils.test.js @@ -404,6 +404,11 @@ describe('Utils', () => { const result = closestBlock(p); window.chai.expect(result).to.equal(p); }); + it('should return null if no block ancestor', () => { + const node = document.createTextNode('\n '); + window.chai.expect(closestBlock(node)).to.equal(null); + window.chai.expect(isVisibleTextNode(node)).to.equal(false); + }); }); describe('lastLeaf', () => { it('should find the last leaf of a child-rich block', () => {