From: Boris Zbarsky Bug 529819. Don't double-add a node to form.elements['foo']. r=smaug diff --git a/content/html/content/src/nsHTMLFormElement.cpp b/content/html/content/src/nsHTMLFormElement.cpp --- a/content/html/content/src/nsHTMLFormElement.cpp +++ b/content/html/content/src/nsHTMLFormElement.cpp @@ -2021,21 +2021,31 @@ nsFormControlList::AddElementToTable(nsG NS_ENSURE_TRUE(nodeList, NS_ERROR_FAILURE); // Upcast, uggly, but it works! nsBaseContentList *list = static_cast ((nsIDOMNodeList *)nodeList.get()); NS_ASSERTION(list->Length() > 1, "List should have been converted back to a single element"); - + + // Fast-path appends; this check is ok even if the child is + // already in the list, since if it tests true the child would + // have come at the end of the list, and the PositionIsBefore + // will test false. if(nsContentUtils::PositionIsBefore(list->GetNodeAt(list->Length() - 1), aChild)) { list->AppendElement(aChild); return NS_OK; } + + // If a control has a name equal to its id, it could be in the + // list already. + if (list->IndexOf(aChild) != -1) { + return NS_OK; + } // first is the first possible insertion index, last is the last possible // insertion index PRUint32 first = 0; PRUint32 last = list->Length() - 1; PRUint32 mid; //Stop when there is only one index in our range diff --git a/content/html/content/test/Makefile.in b/content/html/content/test/Makefile.in --- a/content/html/content/test/Makefile.in +++ b/content/html/content/test/Makefile.in @@ -136,12 +136,13 @@ _TEST_FILES = test_bug589.html \ 347174transformable.xml \ 347174transform.xsl \ test_bug481335.xhtml \ test_bug514856.html \ bug514856_iframe.html \ test_bug519987.html \ test_bug523771.html \ form_submit_server.sjs \ + test_bug529819.html \ $(NULL) libs:: $(_TEST_FILES) $(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir) diff --git a/content/html/content/test/test_bug529819.html b/content/html/content/test/test_bug529819.html new file mode 100644 --- /dev/null +++ b/content/html/content/test/test_bug529819.html @@ -0,0 +1,33 @@ + + + + + Test for Bug 529819 + + + + + +Mozilla Bug 529819 +

+ +
+
+
+ +