Skip to content

Commit 4e7fd2e

Browse files
committed
cleanup
1 parent 237f951 commit 4e7fd2e

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

resources/js/components/TemplateRenderer.vue

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
<script lang="ts">
2-
import { Card, CardContent } from '@/components/ui/card';
3-
import { Badge } from '@/components/ui/badge';
4-
5-
export const components = {
6-
'sharp-card': Card,
7-
'sharp-card-content': CardContent,
8-
'sharp-badge': Badge,
9-
};
10-
</script>
111
<script lang="ts" setup>
122
import { computed } from 'vue';
133
import type { Component } from 'vue';
4+
import { Card, CardContent } from "@/components/ui/card";
5+
import { Badge } from "@/components/ui/badge";
6+
import { sanitizeVueTemplate } from "@/utils/sanitize";
147
158
const props = defineProps<{
169
template: string,
@@ -19,15 +12,13 @@
1912
2013
const component = computed(() => ({
2114
components: {
22-
...components,
15+
'sharp-card': Card,
16+
'sharp-card-content': CardContent,
17+
'sharp-badge': Badge,
2318
...props.components,
2419
},
25-
template: `<div data-sharp-template>${sanitizeForVue(props.template ?? '')}</div>`,
20+
template: `<div data-sharp-template>${sanitizeVueTemplate(props.template ?? '')}</div>`,
2621
}));
27-
28-
function sanitizeForVue(template: string) {
29-
return template.replaceAll('{{', '&lcub;&lcub;').replaceAll('}}', '&rcub;&rcub;');
30-
}
3122
</script>
3223

3324
<template>

resources/js/utils/sanitize.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ export function sanitize(html: string | null) {
1313
})
1414
: html;
1515
}
16+
17+
// Separate function that sanitizes all rendered Vue template, '{{' & '}}' should always be escaped
18+
export function sanitizeVueTemplate(template: string) {
19+
return template.replaceAll('{{', '&lcub;&lcub;').replaceAll('}}', '&rcub;&rcub;');
20+
}

0 commit comments

Comments
 (0)