Skip to content

Commit

Permalink
refactor: tiny improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Dec 15, 2023
1 parent 06bb604 commit fb58a68
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

0 comments on commit fb58a68

Please sign in to comment.