Bug 17461

Summary: querySelectorAll doesn't return correct nodes when using element in element patterns
Product: WebKit Reporter: Moxiecode Systems <spam>
Component: DOMAssignee: Nobody <webkit-unassigned>
Status: RESOLVED INVALID    
Severity: Normal CC: annevk, aroben, borgar
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: All   
Attachments:
Description Flags
Testcase to illustrate the bug. none

Description Moxiecode Systems 2008-02-20 15:38:27 PST
When using the querySelectorAll method on an element it doesn't return the correct number of nodes if a pattern with elements in elements are used.

For example if this code is executed on an element with 4 divs but only one div withing another div it should return 1 and not 4.

document.getElementById('test').querySelectorAll('div div');

HTML:
<div id="test">
	<div>1</div>
	<div>
		<div>2</div>
	</div>
	<div>3</div>
</div>
Comment 1 Moxiecode Systems 2008-02-20 15:40:28 PST
Created attachment 19242 [details]
Testcase to illustrate the bug.

This test case will alert 4 but should alert 1 since only one div is inside another div.
Comment 2 Anne van Kesteren 2008-02-20 15:53:18 PST
I'd mark this INVALID, but can't.

Anyway, selectors are always matched agains the document element. However, for calls on element nodes all nodes not part of the sub tree of that element node are filtered out. This is why you end up with 4 and not 1 or 5.
Comment 3 Anne van Kesteren 2008-02-20 15:56:13 PST
I shouild have mentioned that we will clarify the specification in due course to make this more explicit.
Comment 4 Adam Roben (:aroben) 2008-02-20 15:56:49 PST
Marking INVALID per Anne's comments.
Comment 5 Moxiecode Systems 2008-02-20 16:00:42 PST
Hmm, strange since this is not the way common libraries like jQuery/Prototype etc work. They all return 1 if you scope the search to an specific element so this can't be used as an replacement for those APIs. I could not find anything about this in the W3C specification so I'm wondering what is the correct behavior?
Comment 6 Sam Weinig 2008-03-09 08:14:31 PDT
*** Bug 17731 has been marked as a duplicate of this bug. ***