diff --git a/packages/rich-text-editor/src/vaadin-rich-text-editor-mixin.js b/packages/rich-text-editor/src/vaadin-rich-text-editor-mixin.js index 0f2c5dc7c0..d8cc33bf1f 100644 --- a/packages/rich-text-editor/src/vaadin-rich-text-editor-mixin.js +++ b/packages/rich-text-editor/src/vaadin-rich-text-editor-mixin.js @@ -681,7 +681,7 @@ export const RichTextEditorMixin = (superClass) => return `class="${classes.join(' ')}"`; }); // Remove meta spans, e.g. cursor which are empty after Quill classes removed - content = content.replace(/<\/?span[^>]*>/gu, ''); + content = content.replace(/]*><\/span>/gu, ''); // Replace Quill align classes with inline styles [this.__dir === 'rtl' ? 'left' : 'right', 'center', 'justify'].forEach((align) => { diff --git a/packages/rich-text-editor/test/basic.common.js b/packages/rich-text-editor/test/basic.common.js index fad92c4a8d..8287839909 100644 --- a/packages/rich-text-editor/test/basic.common.js +++ b/packages/rich-text-editor/test/basic.common.js @@ -752,6 +752,12 @@ describe('rich text editor', () => { expect(rte.htmlValue).to.equal('

Hello

world

'); }); + it('should not filter out span elements with style from the resulting htmlValue', () => { + setValueAndFormatText('color', '#e60000'); + // Empty span should be stripped + expect(rte.htmlValue).to.equal('

Foo

'); + }); + it('should not lose leading tab characters from the resulting htmlValue', () => { const htmlWithLeadingTab = '

\tTab

'; rte.dangerouslySetHtmlValue(htmlWithLeadingTab);