added function to escapeHTML

This commit is contained in:
Miodec 2022-06-16 19:00:16 +02:00
parent fe6b74ccf0
commit 3fe1df4370
2 changed files with 17 additions and 1 deletions

View file

@ -33,7 +33,7 @@ class Notification {
}
) {
this.type = type;
this.message = message;
this.message = Misc.escapeHTML(message);
this.level = level;
if (type === "banner") {
this.duration = duration as number;

View file

@ -782,6 +782,22 @@ export function escapeRegExp(str: string): string {
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
const unescapedToEscapedHtml: Record<string, string> = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': "&quot;",
"'": "&#x27;",
"/": "&#x2F;",
};
export function escapeHTML(str: string): string {
return Object.entries(unescapedToEscapedHtml).reduce(
(previous, [current, value]) => previous.replace(current, value),
str
);
}
export function cleanTypographySymbols(textToClean: string): string {
const specials = {
"“": '"', // &ldquo; &#8220;