refactor: sanitize HTML function (#8307)
* refactor: replace isomorphic-dompurify with sanitize-html * dompurify fixes * more fixes with fallback and title * build --------- Co-authored-by: Prateek Shourya <prateekshourya29@gmail.com>
This commit is contained in:
parent
76ebf395e6
commit
e0c97c5471
14 changed files with 235 additions and 260 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import DOMPurify from "dompurify";
|
||||
import sanitizeHtml from "sanitize-html";
|
||||
import type { Content, JSONContent } from "@plane/types";
|
||||
|
||||
/**
|
||||
|
|
@ -120,7 +120,7 @@ const text = stripHTML(html);
|
|||
console.log(text); // Some text
|
||||
*/
|
||||
export const sanitizeHTML = (htmlString: string) => {
|
||||
const sanitizedText = DOMPurify.sanitize(htmlString, { ALLOWED_TAGS: [] }); // sanitize the string to remove all HTML tags
|
||||
const sanitizedText = sanitizeHtml(htmlString, { allowedTags: [] }); // sanitize the string to remove all HTML tags
|
||||
return sanitizedText.trim(); // trim the string to remove leading and trailing whitespaces
|
||||
};
|
||||
|
||||
|
|
@ -155,8 +155,8 @@ export const checkEmailValidity = (email: string): boolean => {
|
|||
};
|
||||
|
||||
export const isEmptyHtmlString = (htmlString: string, allowedHTMLTags: string[] = []) => {
|
||||
// Remove HTML tags using DOMPurify
|
||||
const cleanText = DOMPurify.sanitize(htmlString, { ALLOWED_TAGS: allowedHTMLTags });
|
||||
// Remove HTML tags using sanitize-html
|
||||
const cleanText = sanitizeHtml(htmlString, { allowedTags: allowedHTMLTags });
|
||||
// Trim the string and check if it's empty
|
||||
return cleanText.trim() === "";
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue