Repository navigation
Ignore the form element pointer throughout template contents - #12911
Merged
Merged
Conversation
The form element pointer is deliberately not used inside template contents, but the conditions expressing that only tested the stack of open elements. A fragment parse whose context element is a `template` element produces template contents without ever pushing a `template` element onto that stack, so the pointer was seeded from the context element's ancestors and then used: a nested `<form>` was dropped, and controls could be associated with a form outside the template. Introduce "parsing template contents", which covers that case as well, and use it for the `<form>` start and end tags and when associating a control with the form element pointer. While there, the "in table" `<form>` start tag dropped the element entirely while parsing template contents. It now inserts the element and skips only the pointer assignment, as the "in body" one already did. Also require the parser's fragment context element to be null when associating a control with the form element pointer. No implementation does this during a fragment parse, where the pointer either comes from the context element's ancestors or points into the fragment being built. Association by ancestry is unaffected, so only markup that leaves a control outside its form can tell the difference. Tests: web-platform-tests/wpt#62488 Fixes #12257.
noamr
reviewed
Sep 6, 2026
noamr
approved these changes
Sep 6, 2026
Member
webkit-commit-queue
pushed a commit
to annevk/WebKit
that referenced
this pull request
Sep 8, 2026
…e> context element https://bugs.webkit.org/show_bug.cgi?id=323586 Reviewed by Chris Dumez. The form element pointer is meant to be ignored inside template contents, but isParsingTemplateContents() only consulted the stack of open elements. A fragment parse whose context element is a template element produces template contents without ever pushing a template element onto that stack, so setting innerHTML on a template element used the pointer anyway. Given <form><template id=t></template></form> then t.innerHTML = "<div><form></div><input></form>" dropped the nested <form>, because the pointer had been seeded from the template's form ancestor. Two more cases went wrong without any form ancestor, because a <form> in the markup set the pointer. t.innerHTML = "<form><form>" dropped the second <form>, and t.innerHTML = "<br>BC<form>D<div>E</form>F</div>G" took the pointer-based </form> branch, which removes the form element from the stack of open elements and leaves the <div> open, rather than the branch used for template contents, which pops through it. The same markup written inside <template> in a document produced a different tree as a result. Extend isParsingTemplateContents() to also cover a template context element, and pass the result into insertHTMLFormElement() instead of having it re-derive the narrower condition from the stack of open elements, so the "in body" and "in table" <form> start tags agree with it. Matches whatwg/html#12911. Tests: imported/w3c/web-platform-tests/html/syntax/parsing-html-fragments/fragment-parse-form-in-template-001.html imported/w3c/web-platform-tests/html/syntax/parsing-html-fragments/fragment-parse-form-in-template-002.html imported/w3c/web-platform-tests/html/syntax/parsing-html-fragments/fragment-parse-form-owner-001.html imported/w3c/web-platform-tests/html/syntax/parsing/form-element-pointer-in-template.html Tests upstream: web-platform-tests/wpt#62488 Canonical link: https://commits.webkit.org/320641@main
lexborisov
added a commit
to TimWolla/lexbor
that referenced
this pull request
Sep 26, 2026
The form element pointer is not used inside template contents, but the parser checked only for a template element on the stack of open elements. A fragment parse with a template context element produces template contents without that element on the stack, so a nested form was dropped and a form end tag closed the element the pointer referred to instead of the form in scope. The form start tag in the "in table" insertion mode was also ignored in template contents instead of being inserted. whatwg/html#12911
txgk
added a commit
to gumbo-parser/gumbo-parser
that referenced
this pull request
Sep 27, 2026
fixes 6 new test cases from WPT scenarios added in the last commit whatwg/html#12908 whatwg/html#12911
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The form element pointer is deliberately not used inside template
contents, but the conditions expressing that only tested the stack of
open elements. A fragment parse whose context element is a
templateelement produces template contents without ever pushing a
templateelement onto that stack, so the pointer was seeded from the context
element's ancestors and then used: a nested
<form>was dropped, andcontrols could be associated with a form outside the template.
Introduce "parsing template contents", which covers that case as well,
and use it for the
<form>start and end tags and when associating acontrol with the form element pointer.
While there, the "in table"
<form>start tag dropped the elemententirely while parsing template contents. It now inserts the element and
skips only the pointer assignment, as the "in body" one already did.
Also require the parser's fragment context element to be null when
associating a control with the form element pointer. No implementation
does this during a fragment parse, where the pointer either comes from the
context element's ancestors or points into the fragment being built.
Association by ancestry is unaffected, so only markup that leaves a
control outside its form can tell the difference.
Tests: web-platform-tests/wpt#62488
Fixes #12257.
(See WHATWG Working Mode: Changes for more details.)