Skip to content

Commit b580f35

Browse files
r-farkhutdinovRuslan Farkhutdinov
andauthored
HtmlEditor: Fix type error when parsing list with non-string Delta insert (T1292587) (#30105)
Co-authored-by: Ruslan Farkhutdinov <[email protected]>
1 parent 732a351 commit b580f35

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

packages/devextreme/js/__internal/ui/html_editor/matchers/m_wordLists.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { isString } from '@js/core/utils/type';
2+
13
function getListType(matches) {
24
const prefix = matches[1];
35
return prefix.match(/\S+\./) ? 'ordered' : 'bullet';
@@ -29,6 +31,11 @@ const getMatcher = (quill) => {
2931
const ops = delta.ops.slice();
3032

3133
const insertOperation = ops[0];
34+
35+
if (!isString(insertOperation.insert)) {
36+
return delta;
37+
}
38+
3239
insertOperation.insert = insertOperation.insert.replace(/^\s+/, '');
3340
const listDecoratorMatches = insertOperation.insert.match(/^(\S+)\s+/);
3441
const indent = listDecoratorMatches && getIndent(node, msStyleAttributeName);

packages/devextreme/testing/tests/DevExpress.ui.widgets.htmlEditor/htmlEditorParts/multilineIntegration.tests.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,33 @@ export default function() {
6565
assert.strictEqual(instance.option('value'), prepareTableValue(value));
6666
assert.strictEqual(markup, value);
6767
});
68+
69+
['MsoListParagraphCxSpFirst', 'MsoListParagraphCxSpMiddle', 'MsoListParagraphCxSpLast'].forEach(className => {
70+
test(`editor should not throw error for ${className} class with allowSoftLineBreak (T1292587)`, function(assert) {
71+
const spy = sinon.spy(console, 'error');
72+
const value = `<p class="${className}"><br><br></p>`;
73+
74+
try {
75+
$('#htmlEditor').dxHtmlEditor({ value }).dxHtmlEditor('instance');
76+
77+
assert.strictEqual(spy.called, false, 'No console error was thrown');
78+
} finally {
79+
spy.restore();
80+
}
81+
});
82+
83+
test(`editor should preserve double <br> in list paragraph for ${className} class (T1292587)`, function(assert) {
84+
const value = `<p class="${className}"><br><br></p>`;
85+
const htmlEditor = $('#htmlEditor').dxHtmlEditor({
86+
value
87+
}).dxHtmlEditor('instance');
88+
89+
const markup = htmlEditor.option('value');
90+
const $markup = $('<div>').html(markup);
91+
92+
assert.strictEqual($markup.find('br').length, 2, 'Two soft breaks preserved');
93+
});
94+
});
6895
});
6996

7097
testModule('runtime editing', moduleConfig, function() {

0 commit comments

Comments
 (0)