Bug 1837769 - Associate element with form only if intended parent in same tree. r=dom-core,avandolder

nsHTML5TreeOperation::SetFormElement should only associate an element
with the form, if "the intended parent is in the same tree as the
element pointed to by the form element pointer".

See https://html.spec.whatwg.org/#creating-and-inserting-nodes:parser-inserted-flag

Differential Revision: https://phabricator.services.mozilla.com/D216052
This commit is contained in:
Vincent Hilla
2024-07-23 13:27:05 +00:00
parent d829ca5194
commit 9e51ae885b
4 changed files with 15 additions and 10 deletions

View File

@@ -753,14 +753,15 @@ nsIContentHandle* nsHtml5TreeBuilder::createElement(
if (mBuilder) {
nsHtml5TreeOperation::SetFormElement(
static_cast<nsIContent*>(content),
static_cast<nsIContent*>(aFormElement));
static_cast<nsIContent*>(aFormElement),
static_cast<nsIContent*>(aIntendedParent));
} else {
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement(mozilla::fallible);
if (MOZ_UNLIKELY(!treeOp)) {
MarkAsBrokenAndRequestSuspensionWithoutBuilder(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
}
opSetFormElement operation(content, aFormElement);
opSetFormElement operation(content, aFormElement, aIntendedParent);
treeOp->Init(mozilla::AsVariant(operation));
}
}