Description
When a user copies text from a browser (or any external source) and pastes it into a list paragraph inside the DocumentEditor, the raw SFDT JSON string is inserted into the document as literal text instead of the actual content. Pasting into a regular (non-list) paragraph works correctly.
Version
@syncfusion/ej2-documenteditor 33.1.49 (React)
Steps to Reproduce
- Open a document that contains a bulleted or numbered list.
- Place the cursor inside a list item.
- Copy any text from a browser tab (e.g., a sentence from a webpage).
- Press Ctrl+V inside the list item.
Expected: The copied text is pasted into the list item.
Actual: A raw JSON string (SFDT format) is inserted as literal text, e.g.:
{"sections":[{"blocks":[{"inlines":[{"text":"Hello world"}],"paragraphFormat":{...}}],...}]}
Root Cause (traced in source)
The bug is in Editor.prototype.beforePasteEvent (editor.js). The try/catch block is too broad — it wraps both JSON.parse and pasteContents together:
// editor.js — beforePasteEvent
try {
var parsedData = JSON.parse(data);
this.pasteContents(HelperMethods.getSfdtDocument(parsedData)); // ← throws for list context
} catch (_a) {
// fallback: pastes raw `data` string as-is
this.pasteContents(isNullOrUndefined(data) ? this.copiedTextContent : data);
}
Flow for HTML paste into a list:
- External HTML is sent to the
SystemClipboard service endpoint.
- Service returns SFDT JSON →
data = JSON.stringify(result.data).
beforePasteEvent(data, '.html') is called.
JSON.parse(data) succeeds.
pasteContents(getSfdtDocument(parsedData)) throws (list-context-specific error).
- The
catch block runs pasteContents(data) where data is the raw SFDT JSON string.
- The JSON string is inserted into the document as literal text.
The same paste into a non-list paragraph does not throw in step 5, so it works correctly.
Suggested Fix
Narrow the try/catch so it only guards JSON.parse, not pasteContents:
var parsedData;
try {
parsedData = JSON.parse(data);
} catch (_a) {
// not JSON — paste as plain text
this.pasteContents(isNullOrUndefined(data) ? this.copiedTextContent : data);
return;
}
this.pasteContents(HelperMethods.getSfdtDocument(parsedData));
This way, a failure inside pasteContents is not silently swallowed and does not cause the SFDT JSON to land in the document as text.
Description
When a user copies text from a browser (or any external source) and pastes it into a list paragraph inside the DocumentEditor, the raw SFDT JSON string is inserted into the document as literal text instead of the actual content. Pasting into a regular (non-list) paragraph works correctly.
Version
@syncfusion/ej2-documenteditor33.1.49 (React)Steps to Reproduce
Expected: The copied text is pasted into the list item.
Actual: A raw JSON string (SFDT format) is inserted as literal text, e.g.:
Root Cause (traced in source)
The bug is in
Editor.prototype.beforePasteEvent(editor.js). The try/catch block is too broad — it wraps bothJSON.parseandpasteContentstogether:Flow for HTML paste into a list:
SystemClipboardservice endpoint.data = JSON.stringify(result.data).beforePasteEvent(data, '.html')is called.JSON.parse(data)succeeds.pasteContents(getSfdtDocument(parsedData))throws (list-context-specific error).catchblock runspasteContents(data)wheredatais the raw SFDT JSON string.The same paste into a non-list paragraph does not throw in step 5, so it works correctly.
Suggested Fix
Narrow the try/catch so it only guards
JSON.parse, notpasteContents:This way, a failure inside
pasteContentsis not silently swallowed and does not cause the SFDT JSON to land in the document as text.