fix(editor): Fix Show details summary (#6113)

* 🐛 Fix `Show details` summary

* 🚚 Move constants out of sanitizer
This commit is contained in:
Iván Ovejero
2023-04-28 17:16:46 +02:00
committed by GitHub
parent a72a5112f3
commit 90a62ccfb5
2 changed files with 19 additions and 6 deletions

View File

@@ -1,13 +1,11 @@
import xss, { friendlyAttrValue } from 'xss';
import { ALLOWED_HTML_ATTRIBUTES, ALLOWED_HTML_TAGS } from '@/constants';
/*
Constants and utility functions that help in HTML, CSS and DOM manipulation
*/
export function sanitizeHtml(dirtyHtml: string) {
const allowedAttributes = ['href', 'name', 'target', 'title', 'class', 'id'];
const allowedTags = ['p', 'strong', 'b', 'code', 'a', 'br', 'i', 'em', 'small'];
const sanitizedHtml = xss(dirtyHtml, {
onTagAttr: (tag, name, value) => {
if (tag === 'img' && name === 'src') {
@@ -19,8 +17,7 @@ export function sanitizeHtml(dirtyHtml: string) {
}
}
// Allow `allowedAttributes` and all `data-*` attributes
if (allowedAttributes.includes(name) || name.startsWith('data-')) {
if (ALLOWED_HTML_ATTRIBUTES.includes(name) || name.startsWith('data-')) {
return `${name}="${friendlyAttrValue(value)}"`;
}
@@ -28,7 +25,7 @@ export function sanitizeHtml(dirtyHtml: string) {
// Return nothing, means keep the default handling measure
},
onTag: (tag) => {
if (!allowedTags.includes(tag)) return '';
if (!ALLOWED_HTML_TAGS.includes(tag)) return '';
return;
},
});