Skip to content

Commit

Permalink
refactor: tiny improvements (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Dec 22, 2023
1 parent 06bb604 commit eae31ea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/silver-mayflies-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"domiso": patch
---

refactor: tiny improvements
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 eae31ea

Please sign in to comment.