From fb58a686ff43aec99ba87514976f3aa96df005bd Mon Sep 17 00:00:00 2001 From: JounQin Date: Fri, 15 Dec 2023 15:55:03 +0800 Subject: [PATCH] refactor: tiny improvements --- src/index.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/index.ts b/src/index.ts index 72a3f541..f7aa2d87 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,10 +25,9 @@ function getTagName(el: ChildNode | DocumentOrFragment) { const DISALLOWED_FORM_ATTR_TAG_NAMES = 'button,fieldset,input,label,meter,object,output,select,textarea'.split(',') -const DISALLOWED_ATTR_NAMES = [ - 'autofocus', - ...'fld,formatas,src'.split(',').map(it => `data${it}`), -] +const DISALLOWED_ATTR_NAMES = 'autofocus,datafld,dataformatas,datasrc'.split( + ',', +) const sanitizeAttributes = (el: Element) => { const tagName = getTagName(el) @@ -181,12 +180,10 @@ export const sanitize = ( ), ) - return ( - (fragment && type === TEXT_HTML - ? doc.body.innerHTML - : // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- https://github.com/microsoft/TypeScript/issues/50078 - doc.documentElement?.outerHTML) || '' - ) + return fragment && type === TEXT_HTML + ? doc.body.innerHTML + : // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- https://github.com/microsoft/TypeScript/issues/50078 + doc.documentElement?.outerHTML || '' } export const sanitizeSvg = (svg: string) => sanitize(svg, IMAGE_SVG_XML)