diff options
Diffstat (limited to 'shared/core-utils/renderer')
-rw-r--r-- | shared/core-utils/renderer/html.ts | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/shared/core-utils/renderer/html.ts b/shared/core-utils/renderer/html.ts index 1220848a0..de4ad47ac 100644 --- a/shared/core-utils/renderer/html.ts +++ b/shared/core-utils/renderer/html.ts | |||
@@ -19,3 +19,21 @@ export const SANITIZE_OPTIONS = { | |||
19 | } | 19 | } |
20 | } | 20 | } |
21 | } | 21 | } |
22 | |||
23 | // Thanks: https://stackoverflow.com/a/12034334 | ||
24 | export function escapeHTML (stringParam: string) { | ||
25 | if (!stringParam) return '' | ||
26 | |||
27 | const entityMap = { | ||
28 | '&': '&', | ||
29 | '<': '<', | ||
30 | '>': '>', | ||
31 | '"': '"', | ||
32 | '\'': ''', | ||
33 | '/': '/', | ||
34 | '`': '`', | ||
35 | '=': '=' | ||
36 | } | ||
37 | |||
38 | return String(stringParam).replace(/[&<>"'`=/]/g, s => entityMap[s]) | ||
39 | } | ||