Bug 47166 - querySelectorAll('body>:last-child') does not work unless HTML file ends with 'new-line'.
Summary: querySelectorAll('body>:last-child') does not work unless HTML file ends with...
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC OS X 10.5
: P2 Normal
Assignee: Adam Barth
Depends on:
Reported: 2010-10-05 03:29 PDT by Hayato Ito
Modified: 2010-11-02 12:15 PDT (History)
4 users (show)

See Also:

test1.html (208 bytes, text/html)
2010-10-05 03:29 PDT, Hayato Ito
no flags Details
test2.html (207 bytes, text/html)
2010-10-05 03:30 PDT, Hayato Ito
no flags Details
Patch (4.05 KB, patch)
2010-10-27 23:03 PDT, Adam Barth
eric: review+
eric: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Hayato Ito 2010-10-05 03:29:48 PDT
Created attachment 69768 [details]

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]
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]
Comment 5 Eric Seidel (no email) 2010-10-28 13:41:31 PDT
Comment on attachment 72148 [details]

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>