Bug 148863

Summary: A label element not in a document should not label an element in a document
Product: WebKit Reporter: Ryosuke Niwa <rniwa>
Component: DOMAssignee: Chris Dumez <cdumez>
Severity: Normal CC: cdumez, commit-queue, darin, ggaren, rniwa, sam, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
URL: https://html.spec.whatwg.org/multipage/forms.html#attr-label-for
Description Flags
Patch none

Description Ryosuke Niwa 2015-09-04 18:18:34 PDT
See https://html.spec.whatwg.org/multipage/forms.html#the-label-element

"The 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. If the attribute is specified and there is an element in the Document whose ID is equal to the value of the for attribute, and the first such element is a labelable element, then that element is the label element's labeled control."

When a label element is not in the document, it should not be associated with any form control element.

This bug was found by the newly added test:
Comment 1 Radar WebKit Bug Importer 2015-09-04 18:19:15 PDT
Comment 2 Chris Dumez 2015-10-22 14:06:12 PDT
Created attachment 263860 [details]
Comment 3 Ryosuke Niwa 2015-10-22 21:48:26 PDT
Comment on attachment 263860 [details]

View in context: https://bugs.webkit.org/attachment.cgi?id=263860&action=review

> Source/WebCore/html/HTMLLabelElement.cpp:81
>      // 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 it, otherwise return nullptr.

This is a very wordy comment.  Why don't we just remove this comment and rename
nodeAsSupportedLabelableElement to firstLabelableFormControl?
Comment 4 Chris Dumez 2015-10-23 09:59:57 PDT
Created attachment 263931 [details]
Comment 5 WebKit Commit Bot 2015-10-23 10:48:32 PDT
Comment on attachment 263931 [details]

Clearing flags on attachment: 263931

Committed r191497: <http://trac.webkit.org/changeset/191497>
Comment 6 WebKit Commit Bot 2015-10-23 10:48:37 PDT
All reviewed patches have been landed.  Closing bug.