mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-11-06 11:01:00 +08:00
added function to escapeHTML
This commit is contained in:
parent
fe6b74ccf0
commit
3fe1df4370
2 changed files with 17 additions and 1 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -782,6 +782,22 @@ export function escapeRegExp(str: string): string {
|
|||
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
}
|
||||
|
||||
const unescapedToEscapedHtml: Record<string, string> = {
|
||||
"&": "&",
|
||||
"<": "<",
|
||||
">": ">",
|
||||
'"': """,
|
||||
"'": "'",
|
||||
"/": "/",
|
||||
};
|
||||
|
||||
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 = {
|
||||
"“": '"', // “ “
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue