[whatwg] Serialization of boolean content attributes
Darin Adler
darin at apple.com
Fri Jun 18 10:45:08 PDT 2010
On Jun 18, 2010, at 10:25 AM, Jonas Sicking wrote:
> On Fri, Jun 18, 2010 at 10:15 AM, Alexey Proskuryakov <ap at webkit.org> wrote:
>>
>
>> My reading of HTML5 is that boolean content attributes with no value are serialized as e.g. <option selected="">. That's not what shipping versions of Firefox or IE do, and this markup is invalid per HTML 4, which is a concern for some people.
>>
>> Here are some examples of what Firefox 3.6.3 does, and what would be my preference for WebKit (which currently matches HTML5):
>>
>> <option selected> -> <option selected="selected">
>> <option selected=""> -> <option selected="selected">
>> <option selected="foo"> -> <option selected="foo">
>>
>> IE is different, and serializes all these examples as <option selected>. That wouldn't be my preference, since that's invalid XML, but at least it's valid HTML 4.
>> This is tracked as WebKit bug <https://bugs.webkit.org/show_bug.cgi?id=22678>.
>
> Serializing boolean attributes as <option selected="selected"> seems like a very bad idea since that means that you're changing the value as you serialize. I.e. if you roundtrip by for example setting:
>
> myDivElement.innerHTML = myDivElement.innerHTML
>
> you've change the value of all boolean attribute.
>
> This leaves us with <option selected> or <option selected=""> which both parse to the same DOM in HTML. Given that basically everyone uses the first syntax, I would say that that is what we should serialize as.
>
> Obviously we don't want to serialize it this way in XHTML documents as this isn't valid XML, so there I say we should serialize as <option selected="">
This does mean that for HTML the serialization of the attributes depends on the fact that they are boolean attributes. Currently the serialization algorithm in HTML5 doesn’t handle attributes differently based on their types. Alexey pointed out to me there no obvious way around this unless we want to end up with things like:
<option class>
Instead of:
<option class="">
But I agree that serializing as <option selected> is aesthetically appealing and matches the most popular syntax used in webpages; and the fact that it matches historical IE behavior is a bonus, too.
-- Darin
More information about the whatwg
mailing list