Skip to content

Commit

Permalink
feat: add dompurify
Browse files Browse the repository at this point in the history
  • Loading branch information
swkeep committed Aug 22, 2024
1 parent 126c94d commit 0964d0b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
22 changes: 22 additions & 0 deletions interactionDUI/dui_source/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions interactionDUI/dui_source/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
"format": "prettier . --write"
},
"dependencies": {
"dompurify": "^3.1.6",
"vue": "^3.3.12"
},
"devDependencies": {
"@types/dompurify": "^3.0.5",
"@types/node": "^20.15.0",
"@vitejs/plugin-vue": "^4.5.2",
"eslint": "^9.9.0",
Expand Down
10 changes: 9 additions & 1 deletion interactionDUI/dui_source/src/components/MenuOption.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<input v-if="isRadio" class="menu__option__radio" type="radio" :name="radioName" :checked="isSelected" />
<div class="label" :class="labelClass" :style="computedItemStyle">
<i v-if="item.icon" :class="[item.icon, 'label__icon']"></i>
<span v-if="!isRadio" v-html="item.label"></span>
<span v-if="!isRadio" v-html="sanitizedHTML"></span>
<div v-if="isRadio">
{{ item.label }}
</div>
Expand All @@ -13,12 +13,20 @@
import { computed } from 'vue';
import { Option } from '../types/types';
import { itemStyle } from '../util';
import DOMPurify from 'dompurify';
const props = defineProps<{
item: Option;
selected?: number; // when it's radio
}>();
const sanitizedHTML = computed(() => {
const html = props.item.label;
if (html === undefined) return '';
return DOMPurify.sanitize(html);
});
const isRadio = computed(
() => (props.item.flags?.update || props.item.flags?.action || props.item.flags?.event) ?? false,
);
Expand Down

0 comments on commit 0964d0b

Please sign in to comment.