Bug 47166

Summary: querySelectorAll('body>:last-child') does not work unless HTML file ends with 'new-line'.
Product: WebKit Reporter: Hayato Ito <hayato>
Component: DOMAssignee: Adam Barth <abarth>
Status: RESOLVED FIXED    
Severity: Normal CC: abarth, ap, eric, hamaji
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: OS X 10.5   
Attachments:
Description Flags
test1.html
none
test2.html
none
Patch eric: review+, eric: commit-queue-

Description Hayato Ito 2010-10-05 03:29:48 PDT
Created attachment 69768 [details]
test1.html

Please see attachment files, test1.html and test2.html. The only difference between them is whether there is a 'new-line' at the end of file or not.

- test1.html ends with 'new-line', like '... </html>\n<EOF>'
- test2.html does not end with 'new-line', like '.... </html><EOF>'.

Open each files, then try the following JavaScript code in JavaScript console.

 > document.querySelectorAll('body>:last-child')

The results differs in test1.html and test2.html:
  - In test1.html, querySelectorAll returns a correct result, ['<div id="last">last</div>].
  - In test2.html, querySelectorAll returns an empty list, [], which is wrong result.

This might be a regression because Safari Version 5.0 (6533.16) returns the same correct results for both test1.html and test2.html.
Comment 1 Hayato Ito 2010-10-05 03:30:27 PDT
Created attachment 69769 [details]
test2.html
Comment 2 Adam Barth 2010-10-05 12:59:44 PDT
We had trouble with the last-child selector early on when developing the new tree builder.  There's some API we need to call on an element when it's received its last child (as I recall).  I'll possible we're screwing that up in this case.

The newline at the end of the file gets moved to just inside the body element, which might be confusing something.

Thanks for the report.  I'll take a look.
Comment 3 Adam Barth 2010-10-27 22:32:42 PDT
Looking now.
Comment 4 Adam Barth 2010-10-27 23:03:52 PDT
Created attachment 72148 [details]
Patch
Comment 5 Eric Seidel (no email) 2010-10-28 13:41:31 PDT
Comment on attachment 72148 [details]
Patch

OK.  Your test case is really subtle.  It should document that it's important to not have a newline at the end.

Would probably be clearer if you document.wrote the contnet into an ifram.
Comment 6 Eric Seidel (no email) 2010-10-28 13:41:49 PDT
You mentioned there was a spec bug?  What's the bug?
Comment 7 Adam Barth 2010-10-28 14:00:59 PDT
(In reply to comment #6)
> You mentioned there was a spec bug?  What's the bug?

It's for one of the FIXME cases.  It's just a typo in the spec.
Comment 8 Adam Barth 2010-11-02 12:15:49 PDT
Committed r71147: <http://trac.webkit.org/changeset/71147>