[whatwg] Serialization of boolean content attributes

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="">

/ Jonas

Received on Friday, 18 June 2010 10:25:01 UTC