]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/core-utils/renderer/html.ts
add accept/reject routes for server followers in openapi spec
[github/Chocobozzz/PeerTube.git] / shared / core-utils / renderer / html.ts
index 37ae5147c585460341550d765b7c683cf680de2a..de4ad47ac8569c47d41f89f405fb2af34a273724 100644 (file)
@@ -5,7 +5,7 @@ export const SANITIZE_OPTIONS = {
     a: [ 'href', 'class', 'target', 'rel' ]
   },
   transformTags: {
-    a: (tagName, attribs) => {
+    a: (tagName: string, attribs: any) => {
       let rel = 'noopener noreferrer'
       if (attribs.rel === 'me') rel += ' me'
 
@@ -19,3 +19,21 @@ export const SANITIZE_OPTIONS = {
     }
   }
 }
+
+// Thanks: https://stackoverflow.com/a/12034334
+export function escapeHTML (stringParam: string) {
+  if (!stringParam) return ''
+
+  const entityMap = {
+    '&': '&',
+    '<': '&lt;',
+    '>': '&gt;',
+    '"': '&quot;',
+    '\'': '&#39;',
+    '/': '&#x2F;',
+    '`': '&#x60;',
+    '=': '&#x3D;'
+  }
+
+  return String(stringParam).replace(/[&<>"'`=/]/g, s => entityMap[s])
+}