Verified Commit 70c61e27 authored by Edgar Chen's avatar Edgar Chen Committed by ma1
Browse files

Bug 2046215 - Associate image elements with form only if the form and the...

Bug 2046215 - Associate image elements with form only if the form and the intended parent are in the same tree;  a=RyanVM DONTBUILD

Original Revision: https://phabricator.services.mozilla.com/D305733

Differential Revision: https://phabricator.services.mozilla.com/D309120
parent eafa9906
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -666,6 +666,10 @@ nsIContent* nsHtml5TreeOperation::CreateMathMLElement(

void nsHtml5TreeOperation::SetFormElement(nsIContent* aNode, nsIContent* aForm,
                                          nsIContent* aParent) {
  if (aForm->SubtreeRoot() != aParent->SubtreeRoot()) {
    return;
  }

  RefPtr formElement = HTMLFormElement::FromNodeOrNull(aForm);
  NS_ASSERTION(formElement,
               "The form element doesn't implement HTMLFormElement.");
@@ -674,8 +678,7 @@ void nsHtml5TreeOperation::SetFormElement(nsIContent* aNode, nsIContent* aForm,
      formControl->ControlType() !=
          FormControlType::FormAssociatedCustomElement &&
      !formControl->GetForm() &&
      !aNode->AsElement()->HasAttr(nsGkAtoms::form) &&
      aForm->SubtreeRoot() == aParent->SubtreeRoot()) {
      !aNode->AsElement()->HasAttr(nsGkAtoms::form)) {
    formControl->SetForm(formElement);
  } else if (auto* image = HTMLImageElement::FromNodeOrNull(aNode)) {
    if (!image->GetForm()) {
+6 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
        </script>
        <tr><td><input id='input1'></td></tr>
        <tr><td><input id='input2' form='form1'></td></tr>
        <tr><td><image id='image1'></td></tr>
      </table>
      <form id="form3">
        <input id="input3" />
@@ -37,6 +38,9 @@
          "input3's form owner must be null instead of form2 (as per parsing rules) " +
          "since form2 is not in the same home subtree");

        assert_equals(f['image1'], undefined,
          "image1 must not be a form control of form2 since form2 is not in the same home subtree");

      }, "Controls nested in tables are not associated with form element inside the " +
         "table if the form had been removed by script before the controls were " +
         "inserted by the parser");