diff --git a/libs/designer-ui/src/lib/html/plugins/toolbar/helper/util.ts b/libs/designer-ui/src/lib/html/plugins/toolbar/helper/util.ts index 7fc05fed5c0..13cfaa66dbe 100644 --- a/libs/designer-ui/src/lib/html/plugins/toolbar/helper/util.ts +++ b/libs/designer-ui/src/lib/html/plugins/toolbar/helper/util.ts @@ -126,14 +126,14 @@ export const getDomFromHtmlEditorString = (htmlEditorString: string, nodeMap: Ma // Comments at the start of a DOM are lost when parsing HTML strings, so we wrap the HTML string in a
. const wrappedHtmlEditorString = `
${htmlEditorString}
`; - const purifiedHtmlEditorString = DomPurify.sanitize(encodeURIComponent(wrappedHtmlEditorString), { ADD_TAGS: ['#comment'] }); - const encodedHtmlEditorString = encodeStringSegmentTokensInDomContext(decodeURIComponent(purifiedHtmlEditorString), nodeMap); + const purifiedHtmlEditorString = DomPurify.sanitize(wrappedHtmlEditorString, { ADD_TAGS: ['#comment'] }); + const encodedHtmlEditorString = encodeStringSegmentTokensInDomContext(purifiedHtmlEditorString, nodeMap); - const tempElement = document.createElement('div', {}); - tempElement.innerHTML = encodedHtmlEditorString; + const tempElement = document.createElement('div'); + tempElement.innerHTML = DomPurify.sanitize(encodedHtmlEditorString); // Unwrap the wrapper
. - return tempElement.children[0] as HTMLElement; + return tempElement.firstElementChild as HTMLElement; }; export const isAttributeSupportedByHtmlEditor = (tagName: string, attribute: string): boolean => {