Elements in a node list of the form element's name getter should not be added to...
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Aug 2013 03:46:42 +0000 (03:46 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Aug 2013 03:46:42 +0000 (03:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=120279

Reviewed by Darin Adler.

Source/WebCore:

Don't add the element in the named items to the past names map when there are multiple elements.
This matches IE10's behavior and the specified behavior in HTML5:
http://www.w3.org/TR/2013/WD-html51-20130528/forms.html#dom-form-nameditem

Test: fast/forms/past-names-map-should-not-contain-nodelist-item.html

* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::getNamedElements):

LayoutTests:

Add a regression test.

* fast/forms/past-names-map-should-not-contain-nodelist-item-expected.txt: Added.
* fast/forms/past-names-map-should-not-contain-nodelist-item.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@154662 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/forms/past-names-map-should-not-contain-nodelist-item-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/past-names-map-should-not-contain-nodelist-item.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLFormElement.cpp

index 9184445d18fec4889f34712ea13b4d4319b1cf67..753343e6a6e69872a2ed2375e43190e049375c26 100644 (file)
@@ -1,3 +1,15 @@
+2013-08-26  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Elements in a node list of the form element's name getter should not be added to the past names map
+        https://bugs.webkit.org/show_bug.cgi?id=120279
+
+        Reviewed by Darin Adler.
+
+        Add a regression test.
+
+        * fast/forms/past-names-map-should-not-contain-nodelist-item-expected.txt: Added.
+        * fast/forms/past-names-map-should-not-contain-nodelist-item.html: Added.
+
 2013-08-26  Alexey Proskuryakov  <ap@apple.com>
 
         [Mac] can-read-in-dragstart-event.html and can-read-in-copy-and-cut-events.html fail
diff --git a/LayoutTests/fast/forms/past-names-map-should-not-contain-nodelist-item-expected.txt b/LayoutTests/fast/forms/past-names-map-should-not-contain-nodelist-item-expected.txt
new file mode 100644 (file)
index 0000000..72e8f96
--- /dev/null
@@ -0,0 +1,15 @@
+This test ensures that none of elements in a node list returned by the named getter of a form element are added to the past names map of the element.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS form['foo'].length is 2
+PASS form['foo'][0] is form.firstChild
+PASS form['foo'][1] is form.lastChild
+PASS form.lastChild.name = 'bar'; form['bar'] is form.lastChild
+PASS form.firstChild.name = 'bar'; form['bar'].length is 2
+PASS form['foo'] is undefined.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/past-names-map-should-not-contain-nodelist-item.html b/LayoutTests/fast/forms/past-names-map-should-not-contain-nodelist-item.html
new file mode 100644 (file)
index 0000000..4a8d635
--- /dev/null
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<body>
+<form><input type="text" name="foo"><input type="text" name="foo"></form>
+<script src="../js/resources/js-test-pre.js"></script>
+<script>
+
+description("This test ensures that none of elements in a node list returned by the named getter of a form element are added to the past names map of the element.");
+
+var form = document.querySelector('form');
+shouldBe("form['foo'].length", "2");
+shouldBe("form['foo'][0]", "form.firstChild");
+shouldBe("form['foo'][1]", "form.lastChild");
+shouldBe("form.lastChild.name = 'bar'; form['bar']", "form.lastChild");
+shouldBe("form.firstChild.name = 'bar'; form['bar'].length", "2");
+shouldBeUndefined("form['foo']", "form.firstChild");
+
+form.style.display = 'none';
+
+var successfullyParsed = true;
+
+</script>
+<script src="../js/resources/js-test-post.js"></script>
+</body>
+</html>
index a8532542063b3724cb94c4a8a3b81426b192cf1b..504dfaf9e6f8bbc3306caced6ff49e34d2de2151 100644 (file)
@@ -1,3 +1,19 @@
+2013-08-26  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Elements in a node list of the form element's name getter should not be added to the past names map
+        https://bugs.webkit.org/show_bug.cgi?id=120279
+
+        Reviewed by Darin Adler.
+
+        Don't add the element in the named items to the past names map when there are multiple elements.
+        This matches IE10's behavior and the specified behavior in HTML5:
+        http://www.w3.org/TR/2013/WD-html51-20130528/forms.html#dom-form-nameditem
+
+        Test: fast/forms/past-names-map-should-not-contain-nodelist-item.html
+
+        * html/HTMLFormElement.cpp:
+        (WebCore::HTMLFormElement::getNamedElements):
+
 2013-08-26  Ryosuke Niwa  <rniwa@webkit.org>
 
         Windows build fix after r154658.
index 538a26649ccf1734a740e3165a5a30fa1813448e..6a2714698f849f7701716ce5d9d70a0ae91dcab0 100644 (file)
@@ -639,7 +639,7 @@ void HTMLFormElement::getNamedElements(const AtomicString& name, Vector<RefPtr<N
 
     // FIXME: The specification says we should not add the element from the past when names map when namedItems is not empty.
     HTMLFormControlElement* elementFromPast = elementFromPastNamesMap(name);
-    if (namedItems.size() && namedItems.first() != elementFromPast)
+    if (namedItems.size() == 1 && namedItems.first() != elementFromPast)
         addElementToPastNamesMap(static_cast<HTMLFormControlElement*>(namedItems.first().get()), name);
     else if (elementFromPast && namedItems.find(elementFromPast) == notFound)
         namedItems.append(elementFromPast);