Skip to content

Commit

Permalink
Fix bug in non-boolean attributes being collapsed
Browse files Browse the repository at this point in the history
665a075 introduced a change where non-boolean HTML attributes
(such as `title="title"`) would be stringified as booleans (such as
`title`) if their value was the same as their attribute name.
  • Loading branch information
wooorm committed Jul 18, 2018
1 parent 88a4498 commit 4e8b5c8
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions lib/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,25 +139,33 @@ function attribute(ctx, key, value) {
var schema = ctx.schema
var space = schema.space
var info = find(schema, key)
var name
var name = info.attribute

if (info.overloadedBoolean && (value === name || value === '')) {
value = true
} else if (
info.boolean ||
(info.overloadedBoolean && typeof value !== 'string')
) {
value = Boolean(value)
}

if (
value == null ||
value === false ||
(typeof value === 'number' && isNaN(value)) ||
(!value && info.boolean)
(typeof value === 'number' && isNaN(value))
) {
return EMPTY
}

name = attributeName(ctx, info.attribute)
name = attributeName(ctx, name)

if (value === true || (value && info.boolean)) {
value = name
}
if (value === true) {
if (space === 'html') {
return name
}

if (space === 'html' && value === name) {
return name
value = name
}

return name + attributeValue(ctx, key, value, info)
Expand Down

0 comments on commit 4e8b5c8

Please sign in to comment.