aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-10-17 16:53:10 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-10-17 16:53:10 +0200
commit49347a0a8b64559192d8f29f1237308025a48fd4 (patch)
treefca36cdbd9d0259313234c7e5703276f672364e9 /server/helpers
parentc6e0bfbf582205410bf166118956a368f6a4cbaa (diff)
downloadPeerTube-49347a0a8b64559192d8f29f1237308025a48fd4.tar.gz
PeerTube-49347a0a8b64559192d8f29f1237308025a48fd4.tar.zst
PeerTube-49347a0a8b64559192d8f29f1237308025a48fd4.zip
Escape opengraph/oembed tags
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 '&': '&amp;',
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,