mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-28 01:39:29 +08:00
Fix escapeHTML not working properly and create allowHTML parameter for Notifications. (#3168) rizwanmustafa
* Modify config to allow hot reload on html * Now inject monkeytype.js bundle only in development mode * Remove asset injunction in production * Modify method of escapeHTML * add parameter for allowing html * Allow html for the banner * remove debug log
This commit is contained in:
parent
d869c6f74a
commit
a6f8f54cbf
3 changed files with 21 additions and 19 deletions
|
|
@ -30,10 +30,11 @@ class Notification {
|
|||
customIcon?: string,
|
||||
closeCallback = (): void => {
|
||||
//
|
||||
}
|
||||
},
|
||||
allowHTML?: boolean
|
||||
) {
|
||||
this.type = type;
|
||||
this.message = Misc.escapeHTML(message);
|
||||
this.message = allowHTML ? message : Misc.escapeHTML(message);
|
||||
this.level = level;
|
||||
if (type === "banner") {
|
||||
this.duration = duration as number;
|
||||
|
|
@ -224,7 +225,8 @@ export function add(
|
|||
duration?: number,
|
||||
customTitle?: string,
|
||||
customIcon?: string,
|
||||
closeCallback?: () => void
|
||||
closeCallback?: () => void,
|
||||
allowHTML?: boolean
|
||||
): void {
|
||||
// notificationHistory.push(
|
||||
new Notification(
|
||||
|
|
@ -234,7 +236,8 @@ export function add(
|
|||
duration,
|
||||
customTitle,
|
||||
customIcon,
|
||||
closeCallback
|
||||
closeCallback,
|
||||
allowHTML
|
||||
).show();
|
||||
// );
|
||||
}
|
||||
|
|
@ -244,7 +247,8 @@ export function addBanner(
|
|||
level = -1,
|
||||
customIcon = "bullhorn",
|
||||
sticky = false,
|
||||
closeCallback?: () => void
|
||||
closeCallback?: () => void,
|
||||
allowHTML?: boolean
|
||||
): void {
|
||||
// notificationHistory.push(
|
||||
new Notification(
|
||||
|
|
@ -254,7 +258,8 @@ export function addBanner(
|
|||
sticky ? -1 : 0,
|
||||
undefined,
|
||||
customIcon,
|
||||
closeCallback
|
||||
closeCallback,
|
||||
allowHTML
|
||||
).show();
|
||||
// );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ async function getLatest(): Promise<MonkeyTypes.PSA[]> {
|
|||
"PSA request failed. If this issue persists the server might be experiencing unexpected down time. <a target= '_blank' href='https://monkeytype.instatus.com/'>Check the status page</a> or <a target= '_blank' href='https://twitter.com/monkeytypegame'>Twitter</a> for more information.",
|
||||
-1,
|
||||
"exclamation-triangle",
|
||||
true,
|
||||
undefined,
|
||||
true
|
||||
);
|
||||
return [];
|
||||
|
|
|
|||
|
|
@ -782,20 +782,15 @@ 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
|
||||
);
|
||||
str = str
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
export function cleanTypographySymbols(textToClean: string): string {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue