Skip to content

Commit 4e8b5c8

Browse files
committed
Fix bug in non-boolean attributes being collapsed
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.
1 parent 88a4498 commit 4e8b5c8

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

lib/element.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,25 +139,33 @@ function attribute(ctx, key, value) {
139139
var schema = ctx.schema
140140
var space = schema.space
141141
var info = find(schema, key)
142-
var name
142+
var name = info.attribute
143+
144+
if (info.overloadedBoolean && (value === name || value === '')) {
145+
value = true
146+
} else if (
147+
info.boolean ||
148+
(info.overloadedBoolean && typeof value !== 'string')
149+
) {
150+
value = Boolean(value)
151+
}
143152

144153
if (
145154
value == null ||
146155
value === false ||
147-
(typeof value === 'number' && isNaN(value)) ||
148-
(!value && info.boolean)
156+
(typeof value === 'number' && isNaN(value))
149157
) {
150158
return EMPTY
151159
}
152160

153-
name = attributeName(ctx, info.attribute)
161+
name = attributeName(ctx, name)
154162

155-
if (value === true || (value && info.boolean)) {
156-
value = name
157-
}
163+
if (value === true) {
164+
if (space === 'html') {
165+
return name
166+
}
158167

159-
if (space === 'html' && value === name) {
160-
return name
168+
value = name
161169
}
162170

163171
return name + attributeValue(ctx, key, value, info)

0 commit comments

Comments
 (0)