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 () => {