Skip to content

Commit 943d1f6

Browse files
committed
fix: sanitize and render faq answer as html
1 parent 29829f4 commit 943d1f6

4 files changed

Lines changed: 65 additions & 14 deletions

File tree

apps/frontend/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"radix-vue": "^1.9.5",
4545
"reka-ui": "^2.1.1",
4646
"remixicon": "^3.5.0",
47+
"sanitize-html": "^2.17.1",
4748
"simple-syntax-highlighter": "^3.1.1",
4849
"superjson": "catalog:",
4950
"tailwind-merge": "^2.6.0",
@@ -56,6 +57,7 @@
5657
"@codeanker/eslint-config": "workspace:*",
5758
"@codeanker/typescript-config": "workspace:*",
5859
"@types/node": "catalog:",
60+
"@types/sanitize-html": "^2.16.0",
5961
"@vitejs/plugin-basic-ssl": "^2.1.0",
6062
"@vitejs/plugin-vue": "^6.0.2",
6163
"autoprefixer": "^10.4.16",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import doSanitizeHtml from 'sanitize-html'
2+
3+
export function sanitizeHtml(html: string): string {
4+
return doSanitizeHtml(html, {
5+
allowedTags: [
6+
'p',
7+
'strong',
8+
'em',
9+
'u',
10+
'a',
11+
'ul',
12+
'ol',
13+
'li',
14+
'img',
15+
],
16+
allowedAttributes: {
17+
img: [
18+
'src', 'alt', 'style',
19+
],
20+
},
21+
})
22+
}

apps/frontend/src/views/Anmeldung/components/PublicFAQ.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { injectUnterveranstaltung } from '@/layouts/AnmeldungLayout.vue'
33
import { PlusIcon, MinusIcon } from '@heroicons/vue/24/solid'
44
import { Disclosure, DisclosureButton, DisclosurePanel } from '@headlessui/vue'
5+
import { sanitizeHtml } from '@/helpers/sanitizeHtml';
56
67
const unterveranstaltung = injectUnterveranstaltung()
78
</script>
@@ -57,7 +58,7 @@ const unterveranstaltung = injectUnterveranstaltung()
5758
as="dd"
5859
class="mt-2 pr-12"
5960
>
60-
<p class="text-base/7 text-gray-600">{{ faq.answer }}</p>
61+
<p class="text-base/7 text-gray-600" v-html="sanitizeHtml(faq.answer)"></p>
6162
</DisclosurePanel>
6263
</Disclosure>
6364
</dl>

pnpm-lock.yaml

Lines changed: 39 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)