aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/core-utils.ts17
1 files changed, 17 insertions, 0 deletions
diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.ts
index 3118dc500..33bbdca8b 100644
--- a/server/helpers/core-utils.ts
+++ b/server/helpers/core-utils.ts
@@ -38,6 +38,22 @@ function root () {
38 return join.apply(null, paths) 38 return join.apply(null, paths)
39} 39}
40 40
41// Thanks: https://stackoverflow.com/a/12034334
42function escapeHTML (stringParam) {
43 const entityMap = {
44 '&': '&',
45 '<': '&lt;',
46 '>': '&gt;',
47 '"': '&quot;',
48 "'": '&#39;',
49 '/': '&#x2F;',
50 '`': '&#x60;',
51 '=': '&#x3D;'
52 }
53
54 return String(stringParam).replace(/[&<>"'`=\/]/g, s => entityMap[s])
55}
56
41function promisify0<A> (func: (cb: (err: any, result: A) => void) => void): () => Promise<A> { 57function promisify0<A> (func: (cb: (err: any, result: A) => void) => void): () => Promise<A> {
42 return function promisified (): Promise<A> { 58 return function promisified (): Promise<A> {
43 return new Promise<A>((resolve: (arg: A) => void, reject: (err: any) => void) => { 59 return new Promise<A>((resolve: (arg: A) => void, reject: (err: any) => void) => {
@@ -101,6 +117,7 @@ const statPromise = promisify1<string, Stats>(stat)
101export { 117export {
102 isTestInstance, 118 isTestInstance,
103 root, 119 root,
120 escapeHTML,
104 121
105 promisify0, 122 promisify0,
106 promisify1, 123 promisify1,