-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spec for innerHTML setter with non-HTML context element doesn't seem to match browsers #1376
Comments
@bzbarsky can you correct second testcase because now we don't see them? |
@ArkadiuszMichalski Oops, fixed. |
But why this happend: "Now we run the parser. When the "body" start tag token is output,..."? We get "in body" insertion mode and this mode for "body" make "Parse error" and ignore token, or am I wrong? |
No, because https://html.spec.whatwg.org/multipage/syntax.html#tree-construction-dispatcher says to ignore the current insertion mode and just use the rules at https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inforeign instead. |
Hmm but before we go to tree construction tokenizer should not output some tag? Update: never mind, I read spec more precisely and now its clear. |
The tokenizer outputs tokens, not tags. |
And don't forget about <script>
var div = document.createElementNS("foo", "div");
div.insertAdjacentHTML("afterbegin", "<body><p></p></body>");
document.documentElement.appendChild(document.createTextNode(new XMLSerializer().serializeToString(div)));
</script> Firefox/Chrome output Looks like Gecko in all cases change context to |
Related: https://www.w3.org/Bugs/Public/show_bug.cgi?id=7855 Looking at http://software.hixie.ch/utilities/js/live-dom-viewer/saved/4256 it appears that WebKit and Chromium still parse Without further investigation, I think it would make sense to align the spec with Gecko here. In particular having the HTML parser be able to create elements in other namespaces than HTML/SVG/MathML seems like asking for trouble. cc @hsivonen |
Consider this testcase:
this shows
<div xmlns="foo"><p xmlns="http://www.w3.org/1999/xhtml"></p></div>
in Safari, Chrome, Firefox. In Edge it shows<div xmlns="foo" />
. No idea where the Edge behavior comes from... especially given that this testcase, which per spec should have identical output:shows
<div xmlns="foo"><p xmlns="http://www.w3.org/1999/xhtml"></p></div>
in Edge (and Firefox; it throws in Chrome/Safari).What does the spec say it should output? We start at https://w3c.github.io/DOM-Parsing/#widl-Element-innerHTML and set the context element to the
foo|div
. Then we invoke https://w3c.github.io/DOM-Parsing/#dfn-concept-parse-fragment. The node document is HTML, so we invoke https://html.spec.whatwg.org/multipage/syntax.html#parsing-html-fragments. The tokenization state is set to "data state" (step 4). We letroot
be anhtml|html
and put it on the stack of open elements (step 7). The context element is not a template, so step 8 is irrelevant. In step 9 we create a start tag named "div" but don't really do anything with it so far. In step 10, we find that the stack of open elements has only one thing (thehtml|html|
) and hence use our context node to set the insertion mode. In this case that puts us into the "in body" insertion mode in step 16 of https://html.spec.whatwg.org/multipage/syntax.html#reset-the-insertion-mode-appropriately.Now we run the parser.
When the "body" start tag token is output, we look at https://html.spec.whatwg.org/multipage/syntax.html#tree-construction-dispatcher and see that the adjusted current node is the
foo|div
(because the stack of open elements only has thehtml|html
on it and thefoo|div
is our context element). This adjusted current node is not in the HTML namespace, not a MathML or HTML integration point, so we use the "in foreign content" rules. That lands us at https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inforeign and we match the "A start tag whose tag name is one of .... body" case. This says:So we go to "Any other start tag". The adjusted current node is not MathML or SVG, so we end up doing "Insert a foreign element for the token, in the same namespace as the adjusted current node." This should create a
foo|body
and insert it, as far as I can tell. Clearly this is NOT what any of the browsers actually do.Am I just missing something? @hsivonen, @annevk, help!
// cc @nox
The text was updated successfully, but these errors were encountered: