Commit fbb44563 authored by rniwa@webkit.org's avatar rniwa@webkit.org
Browse files

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.

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: http://svn.webkit.org/repository/webkit/trunk@154662 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 60b759b1
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
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
<!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>
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.
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment