Skip to content

Commit d7a55f6

Browse files
committed
fix(clubInfo): use sanitizeHtml instead of regex to sanitize descriptions
1 parent 36a52de commit d7a55f6

File tree

6 files changed

+60
-15
lines changed

6 files changed

+60
-15
lines changed

components/custom/club-card.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import type { PropType } from 'vue'
33
import type { Club } from '~/types/clubs'
44
import { Button } from '@/components/ui/button'
55
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'
6-
import { cleanHTML, cn } from '@/lib/utils'
6+
import { cn } from '@/lib/utils'
77
import Badge from '@/components/ui/badge/Badge.vue'
8+
import sanitizeHtml from 'sanitize-html'
89
910
const props = defineProps({
1011
club: {
@@ -13,7 +14,9 @@ const props = defineProps({
1314
},
1415
})
1516
16-
const Description_C = cleanHTML(props.club.groups[0].C_DescriptionC)
17+
const Description_C = sanitizeHtml(props.club.groups[0].C_DescriptionC, {
18+
allowedTags: [],
19+
})
1720
</script>
1821

1922
<template>

lib/utils.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,3 @@ export function valueUpdater<T extends Updater<any>>(updaterOrValue: T, ref: Ref
1414
? updaterOrValue(ref.value)
1515
: updaterOrValue
1616
}
17-
18-
export function cleanHTML(content: string): string {
19-
if (!content)
20-
return ''
21-
22-
return content.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi, '')
23-
.replace(/<style[^>]*>([\s\S]*?)<\/style>/gi, '')
24-
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"lucide-vue-next": "^0.441.0",
3939
"ofetch": "^1.3.4",
4040
"radix-vue": "^1.9.5",
41+
"sanitize-html": "^2.13.0",
4142
"tailwind-merge": "^2.5.2",
4243
"tailwindcss-animate": "^1.0.7",
4344
"uncrypto": "^0.1.3",
@@ -61,6 +62,7 @@
6162
"@rollup/plugin-wasm": "^6.2.2",
6263
"@tailwindcss/typography": "^0.5.15",
6364
"@types/node-fetch": "^2.6.11",
65+
"@types/sanitize-html": "^2.13.0",
6466
"@types/uuid": "^10.0.0",
6567
"@types/ws": "^8.5.12",
6668
"dayjs-nuxt": "^2.1.11",

pages/cas/clubs/[id].vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { useRoute } from 'vue-router'
33
import { Button } from '@/components/ui/button'
44
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
5-
import { cleanHTML } from '@/lib/utils'
5+
import sanitizeHtml from 'sanitize-html'
66
import type { Club, Clubs } from '~/types/clubs'
77
88
const { data } = await useFetch<Clubs>('/api/club/all_details')
@@ -30,7 +30,9 @@ let hasDescriptionC = false
3030
let Description_C = ''
3131
3232
if (filteredClubs[0] && filteredClubs[0].groups[0].C_DescriptionC) {
33-
const tempDescription = cleanHTML(filteredClubs[0].groups[0].C_DescriptionC)
33+
const tempDescription = sanitizeHtml(filteredClubs[0].groups[0].C_DescriptionC, {
34+
allowedTags: [],
35+
})
3436
if (tempDescription.trim() !== '') {
3537
Description_C = tempDescription
3638
hasDescriptionC = true

pages/cas/clubs/index.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<script setup lang="ts">
2-
import { onMounted, ref, watch } from 'vue'
2+
import ClubCard from '@/components/custom/club-card.vue'
33
import { Input } from '@/components/ui/input'
4-
import TabsList from '@/components/ui/tabs/TabsList.vue'
54
import Tabs from '@/components/ui/tabs/Tabs.vue'
65
import TabsContent from '@/components/ui/tabs/TabsContent.vue'
6+
import TabsList from '@/components/ui/tabs/TabsList.vue'
77
import TabsTrigger from '@/components/ui/tabs/TabsTrigger.vue'
8-
import ClubCard from '@/components/custom/club-card.vue'
8+
import { onMounted, ref, watch } from 'vue'
99
1010
import type { Club, ClubCategoryKey, Clubs, Groups } from '~/types/clubs'
1111

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)