Skip to content

Commit f490b2e

Browse files
author
Katja Potensky
committed
exempt string values from being treated as known booleans unless empty or equal to name
1 parent fb74df8 commit f490b2e

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

Diff for: 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
}

Diff for: test/attribute.js

+44
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ test('`element` attributes', async (t) => {
140140
}
141141
)
142142

143+
// TODO: why? "hidden" is a valid value for the `hidden` attribute
143144
await t.test(
144145
'should serialize known booleans set to their name without value',
145146
async function () {
@@ -161,6 +162,49 @@ test('`element` attributes', async (t) => {
161162
)
162163
}
163164
)
165+
166+
await t.test(
167+
'should serialize known booleans set to arbitrary strings with value',
168+
async function () {
169+
assert.deepEqual(
170+
toHtml(
171+
h('div', {
172+
selected: 'some string value for a well known boolean attribute'
173+
})
174+
),
175+
'<div selected="some string value for a well known boolean attribute"></div>'
176+
)
177+
}
178+
)
179+
180+
await t.test(
181+
'should serialize known booleans set to an empty string without value',
182+
async function () {
183+
assert.deepEqual(
184+
toHtml(
185+
h('div', {
186+
selected: ''
187+
})
188+
),
189+
'<div selected></div>'
190+
)
191+
}
192+
)
193+
194+
await t.test(
195+
'should serialize known overloaded booleans set to arbitrary strings with value',
196+
async function () {
197+
assert.deepEqual(
198+
toHtml(
199+
h('div', {
200+
download:
201+
'some string value for a well known overloaded boolean attribute'
202+
})
203+
),
204+
'<div download="some string value for a well known overloaded boolean attribute"></div>'
205+
)
206+
}
207+
)
164208
})
165209

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

0 commit comments

Comments
 (0)