This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 17216 - Fragment serialization doesn't handle the case when 'the node' is a void element yet has child nodes
Summary: Fragment serialization doesn't handle the case when 'the node' is a void elem...
Status: RESOLVED INVALID
Alias: None
Product: HTML WG
Classification: Unclassified
Component: HTML5 spec (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: Ian 'Hixie' Hickson
QA Contact: HTML WG Bugzilla archive list
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-28 07:48 UTC by Olli Pettay
Modified: 2012-05-28 09:05 UTC (History)
4 users (show)

See Also:


Attachments

Description Olli Pettay 2012-05-28 07:48:26 UTC
If someone does <input>.appendChild(document.createElement("div"));
per http://html5.org/specs/dom-parsing.html#innerhtml and 
http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#html-fragment-serialization-algorithm
<input>.innerHTML would become "<div></div>".
That doesn't look right, given that if <input> element is handled as a 
child of some element which is being serialized, the div element wouldn't
end up to the innerHTML serialization.

So, I believe http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#html-fragment-serialization-algorithm should
handle the case when 'the node' is a void element and return empty string
in such case.
Comment 1 Simon Pieters 2012-05-28 08:03:39 UTC
Why? You can still set <input>.innerHTML = '<div></div>'.

Since void elements can have children in XML or with DOM API, I don't see the point in changing this.
Comment 2 Olli Pettay 2012-05-28 08:11:54 UTC
(In reply to comment #1)
> Why? You can still set <input>.innerHTML = '<div></div>'.

You can, but why is it expected that that actually parses something?

> 
> Since void elements can have children in XML or with DOM API, I don't see the
> point in changing this.
It is strange inconsistency in the innerHTML serialization that it depends
on the context where you use innerHTML what gets serialized.
I mean, in some cases the contents of a void element is serialized, but in some
cases it isn't.
Comment 3 Simon Pieters 2012-05-28 08:26:10 UTC
(In reply to comment #2)
> You can, but why is it expected that that actually parses something?

Because it's what most browsers did when this was specified, I think.
Comment 4 Olli Pettay 2012-05-28 09:01:38 UTC
Ok, Ms2ger gave yet another bad case.
Ms2ger:	<img><div><span></span></div></img>, what's div.innerHTML?

So, ok, serialization is broken by design.
I don't care enough, and I can close this bug.
Comment 5 Aryeh Gregor 2012-05-28 09:05:40 UTC
FWIW, from Live DOM Viewer:

<!DOCTYPE html>
<img>
<script>
document.body.firstChild.appendChild(document.createElement("div"));
w(document.body.firstChild.innerHTML);
</script>

This outputs the empty string in Chrome 21 dev and Opera Next 12.00 alpha, and "<div></div>" in IE10(ish) and Firefox 15.0a1.