Skip to content

Commit 6000808

Browse files
authored
Fix to allow other strings for boolean attributes
Closes GH-45. Closes GH-46. Reviewed-by: Titus Wormer <[email protected]>
1 parent fb74df8 commit 6000808

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

lib/handle/element.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ function serializeAttribute(state, key, value) {
173173
if (info.overloadedBoolean && (value === info.attribute || value === '')) {
174174
value = true
175175
} else if (
176-
info.boolean ||
177-
(info.overloadedBoolean && typeof value !== 'string')
176+
(typeof value !== 'string' || value === '' || value === info.attribute) &&
177+
(info.boolean || info.overloadedBoolean)
178178
) {
179179
value = Boolean(value)
180180
}

test/attribute.js

+43
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,49 @@ test('`element` attributes', async (t) => {
161161
)
162162
}
163163
)
164+
165+
await t.test(
166+
'should serialize known booleans set to arbitrary strings with value',
167+
async function () {
168+
assert.deepEqual(
169+
toHtml(
170+
h('div', {
171+
selected: 'some string value for a well known boolean attribute'
172+
})
173+
),
174+
'<div selected="some string value for a well known boolean attribute"></div>'
175+
)
176+
}
177+
)
178+
179+
await t.test(
180+
'should serialize known booleans set to an empty string without value',
181+
async function () {
182+
assert.deepEqual(
183+
toHtml(
184+
h('div', {
185+
selected: ''
186+
})
187+
),
188+
'<div selected></div>'
189+
)
190+
}
191+
)
192+
193+
await t.test(
194+
'should serialize known overloaded booleans set to arbitrary strings with value',
195+
async function () {
196+
assert.deepEqual(
197+
toHtml(
198+
h('div', {
199+
download:
200+
'some string value for a well known overloaded boolean attribute'
201+
})
202+
),
203+
'<div download="some string value for a well known overloaded boolean attribute"></div>'
204+
)
205+
}
206+
)
164207
})
165208

166209
await t.test('should support known overloaded booleans', async function (t) {

0 commit comments

Comments
 (0)