https://bugs.webkit.org/show_bug.cgi?id=120432
Reviewed by Anders Carlsson.
Source/WebCore:
Don't add the element from the past names map if we've found elements of the given name.
Test: fast/forms/past-names-map-should-be-used-only-when-named-item-is-empty.html
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::getNamedElements):
LayoutTests:
Add a regression test so that we never regress again.
* fast/forms/past-names-map-should-be-used-only-when-named-item-is-empty-expected.txt: Added.
* fast/forms/past-names-map-should-be-used-only-when-named-item-is-empty.html: Added.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@154765
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2013-08-28 Ryosuke Niwa <rniwa@webkit.org>
+
+ REGRESSION(r154586): Past names map should only be used when named item is empty
+ https://bugs.webkit.org/show_bug.cgi?id=120432
+
+ Reviewed by Anders Carlsson.
+
+ Add a regression test so that we never regress again.
+
+ * fast/forms/past-names-map-should-be-used-only-when-named-item-is-empty-expected.txt: Added.
+ * fast/forms/past-names-map-should-be-used-only-when-named-item-is-empty.html: Added.
+
2013-08-28 Ryosuke Niwa <rniwa@webkit.org>
Fix a typo in the test name.
--- /dev/null
+PASS form['foo'] is form.childNodes[0]
+PASS form['bar'][0] is form.childNodes[1]
+PASS form['bar'][1] is form.childNodes[2]
+PASS form.childNodes[0].name = 'bar'; form.childNodes[1].name = form.childNodes[2].name = 'foo'; form['foo'].length is 2
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
--- /dev/null
+<!DOCTYPE html>
+<html>
+<body>
+<form><input type="text" name="foo"><input type="text" name="bar"><input type="text" name="bar"></form>
+<script src="../js/resources/js-test-pre.js"></script>
+<script>
+
+var form = document.querySelector('form');
+shouldBe("form['foo']", "form.childNodes[0]");
+shouldBe("form['bar'][0]", "form.childNodes[1]");
+shouldBe("form['bar'][1]", "form.childNodes[2]");
+shouldBe("form.childNodes[0].name = 'bar'; form.childNodes[1].name = form.childNodes[2].name = 'foo'; form['foo'].length", "2");
+
+var successfullyParsed = true;
+
+</script>
+<script src="../js/resources/js-test-post.js"></script>
+</body>
+</html>
+2013-08-28 Ryosuke Niwa <rniwa@webkit.org>
+
+ REGRESSION(r154586): Past names map should only be used when named item is empty
+ https://bugs.webkit.org/show_bug.cgi?id=120432
+
+ Reviewed by Anders Carlsson.
+
+ Don't add the element from the past names map if we've found elements of the given name.
+
+ Test: fast/forms/past-names-map-should-be-used-only-when-named-item-is-empty.html
+
+ * html/HTMLFormElement.cpp:
+ (WebCore::HTMLFormElement::getNamedElements):
+
2013-08-27 Ryosuke Niwa <rniwa@webkit.org>
Don't keep unassociated elements in the past names map
// http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#dom-form-nameditem
elements()->namedItems(name, namedItems);
- // FIXME: The specification says we should not add the element from the past when names map when namedItems is not empty.
HTMLElement* elementFromPast = elementFromPastNamesMap(name);
if (namedItems.size() == 1 && namedItems.first() != elementFromPast)
addToPastNamesMap(toHTMLElement(namedItems.first().get())->asFormNamedItem(), name);
- else if (elementFromPast && namedItems.find(elementFromPast) == notFound)
+ else if (elementFromPast && namedItems.isEmpty())
namedItems.append(elementFromPast);
}