From 335dd9a1e436ea1674fbd0681caea286d8ea38df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Geelen=20=28sge=29?= Date: Fri, 28 Apr 2023 06:55:09 +0000 Subject: [PATCH] [FIX] web_editor: delete comment nodes on sanitize MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit During `to_inline` process, the document will be transformed to be email friendly. This can add some `` comment into the document. These comments nodes will create issues during future edition, if we keep them in the editable. So we add a sanitize step to remove all comments nodes. task-3222474 closes odoo/odoo#124020 X-original-commit: b85a29d9ba36aaaa90e514ba45d1054b693a26e2 Signed-off-by: David Monjoie (dmo) Signed-off-by: Geelen Sébastien (sge) --- addons/web_editor/static/src/js/backend/html_field.js | 1 + .../src/js/editor/odoo-editor/src/utils/sanitize.js | 5 +++++ .../src/js/editor/odoo-editor/test/spec/editor.test.js | 9 +++++++++ 3 files changed, 15 insertions(+) diff --git a/addons/web_editor/static/src/js/backend/html_field.js b/addons/web_editor/static/src/js/backend/html_field.js index 477d5bd6786..8ba88b1e815 100644 --- a/addons/web_editor/static/src/js/backend/html_field.js +++ b/addons/web_editor/static/src/js/backend/html_field.js @@ -575,6 +575,7 @@ export class HtmlField extends Component { */ async _toInline() { const $editable = this.wysiwyg.getEditable(); + this.wysiwyg.odooEditor.sanitize(this.wysiwyg.odooEditor.editable); const html = this.wysiwyg.getValue(); const $odooEditor = $editable.closest('.odoo-editor-editable'); // Save correct nodes references. diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/sanitize.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/sanitize.js index 20f09f5c1d2..359cb18c9c6 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/sanitize.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/sanitize.js @@ -149,6 +149,11 @@ class Sanitize { node = nodeP; } + // Remove comment nodes to avoid issues with mso comments. + if (node.nodeType === Node.COMMENT_NODE) { + node.remove(); + } + const selection = this.root.ownerDocument.getSelection(); const anchor = selection && selection.anchorNode; const anchorEl = anchor && closestElement(anchor); diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/editor.test.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/editor.test.js index bf1213690f9..c17c3a37480 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/editor.test.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/editor.test.js @@ -5778,6 +5778,15 @@ X[] }); }); + describe('comment node', () => { + it('should remove comment node inside editable content during sanitize', async () => { + await testEditor(BasicEditor, { + contentBefore: '

abcd

', + contentAfter: '

abcd

', + }); + }); + }); + describe('markdown', () => { describe('inline code', () => { it('should convert text into inline code (start)', async () => {