Title: [191497] trunk
Revision
191497
Author
[email protected]
Date
2015-10-23 10:47:49 -0700 (Fri, 23 Oct 2015)

Log Message

A label element not in a document should not label an element in a document
https://bugs.webkit.org/show_bug.cgi?id=148863
<rdar://problem/22589300>

Reviewed by Ryosuke Niwa.

LayoutTests/imported/w3c:

Rebaseline W3C HTML test now that one more check is passing.

* web-platform-tests/html/semantics/forms/the-label-element/label-attributes-expected.txt:

Source/WebCore:

As per the HTML specification, a label element's 'for' attribute may be
specified to indicate a form control with which the caption is to be
associated. If the attribute is specified, the attribute's value must
be the ID of a labelable element in the same Document as the label
element:
https://html.spec.whatwg.org/multipage/forms.html#attr-label-for

However, our code was failing to check if the label element was actually
in the document before calling document.getElementById(). In such case,
we would potentially return a labelable Element that is not in the same
document as the label Element. This patch fixes the problem.

The new behavior is consistent with Firefox.

No new tests, already covered by existing test.

* html/HTMLLabelElement.cpp:
(WebCore::HTMLLabelElement::control):

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (191496 => 191497)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2015-10-23 17:11:02 UTC (rev 191496)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2015-10-23 17:47:49 UTC (rev 191497)
@@ -1,3 +1,15 @@
+2015-10-23  Chris Dumez  <[email protected]>
+
+        A label element not in a document should not label an element in a document
+        https://bugs.webkit.org/show_bug.cgi?id=148863
+        <rdar://problem/22589300>
+
+        Reviewed by Ryosuke Niwa.
+
+        Rebaseline W3C HTML test now that one more check is passing.
+
+        * web-platform-tests/html/semantics/forms/the-label-element/label-attributes-expected.txt:
+
 2015-10-21  Chris Dumez  <[email protected]>
 
         Un-expose obsolete HTMLBaseFontElement

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-label-element/label-attributes-expected.txt (191496 => 191497)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-label-element/label-attributes-expected.txt	2015-10-23 17:11:02 UTC (rev 191496)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-label-element/label-attributes-expected.txt	2015-10-23 17:47:49 UTC (rev 191497)
@@ -1,6 +1,6 @@
 
 PASS A label element with a 'for' attribute should only be associated with a labelable element. 
-FAIL A label element not in a document can not label any element in the document. assert_not_equals: A label element not in a document should not label an element in a document. got disallowed value Element node <input id="test1"></input>
+PASS A label element not in a document can not label any element in the document. 
 PASS The labeled control for a label element that has no 'for' attribute is the first labelable element which is a descendant of that label element. 
 PASS The 'for' attribute points to an inexistent id. 
 PASS A non-control follows by a control with same ID. 

Modified: trunk/Source/WebCore/ChangeLog (191496 => 191497)


--- trunk/Source/WebCore/ChangeLog	2015-10-23 17:11:02 UTC (rev 191496)
+++ trunk/Source/WebCore/ChangeLog	2015-10-23 17:47:49 UTC (rev 191497)
@@ -1,3 +1,30 @@
+2015-10-23  Chris Dumez  <[email protected]>
+
+        A label element not in a document should not label an element in a document
+        https://bugs.webkit.org/show_bug.cgi?id=148863
+        <rdar://problem/22589300>
+
+        Reviewed by Ryosuke Niwa.
+
+        As per the HTML specification, a label element's 'for' attribute may be
+        specified to indicate a form control with which the caption is to be
+        associated. If the attribute is specified, the attribute's value must
+        be the ID of a labelable element in the same Document as the label
+        element:
+        https://html.spec.whatwg.org/multipage/forms.html#attr-label-for
+
+        However, our code was failing to check if the label element was actually
+        in the document before calling document.getElementById(). In such case,
+        we would potentially return a labelable Element that is not in the same
+        document as the label Element. This patch fixes the problem.
+
+        The new behavior is consistent with Firefox.
+
+        No new tests, already covered by existing test.
+
+        * html/HTMLLabelElement.cpp:
+        (WebCore::HTMLLabelElement::control):
+
 2015-10-23  Antoine Quint  <[email protected]>
 
         Support for SVG `beginEvent` event and `onbegin` attribute

Modified: trunk/Source/WebCore/html/HTMLLabelElement.cpp (191496 => 191497)


--- trunk/Source/WebCore/html/HTMLLabelElement.cpp	2015-10-23 17:11:02 UTC (rev 191496)
+++ trunk/Source/WebCore/html/HTMLLabelElement.cpp	2015-10-23 17:47:49 UTC (rev 191497)
@@ -36,12 +36,14 @@
 
 using namespace HTMLNames;
 
-static LabelableElement* nodeAsSupportedLabelableElement(Node* node)
+static LabelableElement* firstElementWithIdIfLabelable(TreeScope& treeScope, const AtomicString& id)
 {
-    if (!is<LabelableElement>(node))
+    auto* element = treeScope.getElementById(id);
+    if (!is<LabelableElement>(element))
         return nullptr;
-    LabelableElement& element = downcast<LabelableElement>(*node);
-    return element.supportLabels() ? &element : nullptr;
+
+    auto& labelableElement = downcast<LabelableElement>(*element);
+    return labelableElement.supportLabels() ? &labelableElement : nullptr;
 }
 
 inline HTMLLabelElement::HTMLLabelElement(const QualifiedName& tagName, Document& document)
@@ -74,9 +76,7 @@
         return nullptr;
     }
     
-    // Find the first element whose id is controlId. If it is found and it is a labelable form control,
-    // return it, otherwise return 0.
-    return nodeAsSupportedLabelableElement(treeScope().getElementById(controlId));
+    return inDocument() ? firstElementWithIdIfLabelable(treeScope(), controlId) : nullptr;
 }
 
 HTMLFormElement* HTMLLabelElement::form() const
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to