From 26a6f95540540d9fb1ac07da55d3e97438afd8a2 Mon Sep 17 00:00:00 2001 From: Andrew Simachev Date: Fri, 6 Jun 2025 12:14:24 +0200 Subject: [PATCH] fix latex --- src/ts/component/form/editable.tsx | 2 +- src/ts/lib/util/common.ts | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/ts/component/form/editable.tsx b/src/ts/component/form/editable.tsx index c7bf30520f..1ad90f2343 100644 --- a/src/ts/component/form/editable.tsx +++ b/src/ts/component/form/editable.tsx @@ -98,7 +98,7 @@ const Editable = forwardRef(({ }; const setValue = (html: string) => { - $(editableRef.current).get(0).innerHTML = U.Common.sanitize(html); + $(editableRef.current).get(0).innerHTML = U.Common.sanitize(html, true); }; const getTextValue = (): string => { diff --git a/src/ts/lib/util/common.ts b/src/ts/lib/util/common.ts index 735f3469ab..85a6734378 100644 --- a/src/ts/lib/util/common.ts +++ b/src/ts/lib/util/common.ts @@ -1324,7 +1324,7 @@ class UtilCommon { * @param {string} s - The string to sanitize. * @returns {string} The sanitized string. */ - sanitize (s: string): string { + sanitize (s: string, withStyles?: boolean): string { s = String(s || ''); if (!TEST_HTML.test(s)) { @@ -1332,13 +1332,18 @@ class UtilCommon { }; const tags = [ 'b', 'br', 'a', 'ul', 'li', 'h1', 'span', 'p', 'name', 'smile', 'img' ].concat(Object.values(Mark.getTags())); - - return DOMPurify.sanitize(s, { + const param: any = { ADD_TAGS: tags, ADD_ATTR: [ 'contenteditable' ], ALLOWED_URI_REGEXP: /^(?:(?:[a-z]+):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i, - FORBID_ATTR: [ 'style' ], - }); + FORBID_ATTR: [], + }; + + if (!withStyles) { + param.FORBID_ATTR.push('style'); + }; + + return DOMPurify.sanitize(s, param); }; /**