diff --git a/lib/handle/element.js b/lib/handle/element.js index 17b4713..f20a58b 100644 --- a/lib/handle/element.js +++ b/lib/handle/element.js @@ -173,8 +173,8 @@ function serializeAttribute(state, key, value) { if (info.overloadedBoolean && (value === info.attribute || value === '')) { value = true } else if ( - info.boolean || - (info.overloadedBoolean && typeof value !== 'string') + (typeof value !== 'string' || value === '' || value === info.attribute) && + (info.boolean || info.overloadedBoolean) ) { value = Boolean(value) } diff --git a/test/attribute.js b/test/attribute.js index 99e2a5e..5180737 100644 --- a/test/attribute.js +++ b/test/attribute.js @@ -161,6 +161,49 @@ test('`element` attributes', async (t) => { ) } ) + + await t.test( + 'should serialize known booleans set to arbitrary strings with value', + async function () { + assert.deepEqual( + toHtml( + h('div', { + selected: 'some string value for a well known boolean attribute' + }) + ), + '
' + ) + } + ) + + await t.test( + 'should serialize known booleans set to an empty string without value', + async function () { + assert.deepEqual( + toHtml( + h('div', { + selected: '' + }) + ), + '' + ) + } + ) + + await t.test( + 'should serialize known overloaded booleans set to arbitrary strings with value', + async function () { + assert.deepEqual( + toHtml( + h('div', { + download: + 'some string value for a well known overloaded boolean attribute' + }) + ), + '' + ) + } + ) }) await t.test('should support known overloaded booleans', async function (t) {