Bug 148863 - A label element not in a document should not label an element in a document
Summary: A label element not in a document should not label an element in a document
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL: https://html.spec.whatwg.org/multipag...
Keywords: InRadar
Depends on:
Reported: 2015-09-04 18:18 PDT by Ryosuke Niwa
Modified: 2015-10-23 10:48 PDT (History)
7 users (show)

See Also:

Patch (4.32 KB, patch)
2015-10-22 14:06 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (5.08 KB, patch)
2015-10-23 09:59 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.