Skip to content

Commit

Permalink
fix: handle falsy properties
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed Jul 30, 2023
1 parent 158ff5b commit 706d692
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
13 changes: 8 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function attributesToString (attributes) {
const keys = Object.keys(attributes)
const length = keys.length

let key, value, formattedName, escaped
let key, value, formattedName
let result = ''
let index = 0

Expand Down Expand Up @@ -211,12 +211,15 @@ function attributesToString (attributes) {

continue
}


if (value === null || value === undefined) {
continue
}

result += ' ' + formattedName
escaped = escapeHtml(value)

if (escaped !== '') {
result += '="' + escaped + '"'
if (value !== '') {
result += '="' + escapeHtml(value) + '"'
}
}

Expand Down
5 changes: 5 additions & 0 deletions test/falsy.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ test('falsy values', () => {
</>,
'false'
)

assert.equal(
<div id="truthy" hidden={false} spellcheck={true} translate={undefined}></div>,
'<div id="truthy" spellcheck></div>'
)
})

0 comments on commit 706d692

Please sign in to comment.