Closed golightlyb closed 5 years ago
Thanks for finding this bug.
I am a bit hesitant about this PR, as some time in the future I'm going to receive a bug report about tag['data-foo'] = False
not correctly rendering as <tag data-foo="false">
. There is no easy way to fix this without maintaining a whitelist of tags and their boolean attributes.
However, since I'm already special casing the True
value it seems only consistent to do both (and I can see the value where you just want to pass a boolean and have it render correctly without having to make your own conditionals), and since this is clearly a bug in more common tags, it seems like a good idea.
Thanks for the review - I have made those changes.
RE: tag['data-foo'] = False
not correctly rendering as <tag data-foo="false">
I'd suggest, if that's what someone wants, do explicitly: tag['data-foo'] = "false"
Edit
As an aside, for example:this is what you would have to do for example with the spellcheck
attribute, which is uniquely weird and is the only attribute that I know of that takes only the strings "true"
or "false"
(and nothing else)
You might be interested in this project I made that handles the various boolean and boolean-enumeration types:
HTML 5.2, W3C Recommendation, 14 December 2017 https://www.w3.org/TR/html5/infrastructure.html#boolean-attribute
Expected behaviour is demonstrated by the included test case: