REGRESSION(r154586): Past names map should only be used when named item is empty
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 28 Aug 2013 19:00:01 +0000 (19:00 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 28 Aug 2013 19:00:01 +0000 (19:00 +0000)
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

LayoutTests/ChangeLog
LayoutTests/fast/forms/past-names-map-should-be-used-only-when-named-item-is-empty-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/past-names-map-should-be-used-only-when-named-item-is-empty.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLFormElement.cpp

index 5ec0b9f1cc831529703e34647eae1c4448d85d4e..4341ca6d9a2f97a1ff726fd04864952862573cf2 100644 (file)
@@ -1,3 +1,15 @@
+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.
diff --git a/LayoutTests/fast/forms/past-names-map-should-be-used-only-when-named-item-is-empty-expected.txt b/LayoutTests/fast/forms/past-names-map-should-be-used-only-when-named-item-is-empty-expected.txt
new file mode 100644 (file)
index 0000000..b5b740b
--- /dev/null
@@ -0,0 +1,8 @@
+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
+
diff --git a/LayoutTests/fast/forms/past-names-map-should-be-used-only-when-named-item-is-empty.html b/LayoutTests/fast/forms/past-names-map-should-be-used-only-when-named-item-is-empty.html
new file mode 100644 (file)
index 0000000..df21000
--- /dev/null
@@ -0,0 +1,19 @@
+<!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>
index c9c84735e2bcba37149856b6f2efa57d5ea6691a..9d16e8dfcd9d6a440f46207a23bf4deb69d6ed72 100644 (file)
@@ -1,3 +1,17 @@
+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
index efc398f07d2ee0f3bb6e477d2b41defcfe88af04..bdfcc584de43937a19377f2633671bfb12a21936 100644 (file)
@@ -678,11 +678,10 @@ void HTMLFormElement::getNamedElements(const AtomicString& name, Vector<RefPtr<N
     // 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);
 }