querySelectorAll nth-child returns inaccurate results

VERIFIED FIXED in Firefox 6

Status

()

Core
DOM
P1
normal
VERIFIED FIXED
6 years ago
6 years ago

People

(Reporter: Brian Kardell, Assigned: bz)

Tracking

Trunk
mozilla7
Points:
---
Bug Flags:
in-testsuite +

Firefox Tracking Flags

(firefox5 affected, firefox6+ fixed)

Details

Attachments

(2 attachments, 1 obsolete attachment)

(Reporter)

Description

6 years ago
Created attachment 542207 [details]
Numerous examples illustrating query

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:5.0) Gecko/20100101 Firefox/5.0
Build ID: 20110615151330

Steps to reproduce:

Was experiencing a problem in jquery, but it seems due to delegation to querySelector all. Created a test page and verified that CSS and querySelector all give me the same results for an nth-child(4n) style selector in other browsers, but not in FF 5.


Actual results:

CSS appears to match other browsers (and spec) but querySelectorAll results in different matches in FF5.


Expected results:

CSS and querySelectorAll should have the same result for the same selector.

Updated

6 years ago
Component: General → DOM
Product: Firefox → Core
QA Contact: general → general
Attachment #542207 - Attachment filename: live.html → test.html
Attachment #542207 - Attachment filename: test.html → live.html
Attachment #542207 - Attachment mime type: text/plain → text/html
Argh.  This is a bug in the nth-index cache.  What happens is that we only have  cached values for the <div>s and we end up adding 1 to the previous cached value we find.  That's broken, of course.

In Gecko 2.0, we only looked at the immediate previous sibling, so adding just 1 was correct.

We should get this fixed on aurora (Fx6) in addition to m-c, I think.
Assignee: nobody → bzbarsky
Blocks: 598832
Status: UNCONFIRMED → NEW
tracking-firefox6: --- → ?
tracking-firefox7: --- → ?
Ever confirmed: true
Priority: -- → P1
Version: 5 Branch → Trunk
Created attachment 542219 [details] [diff] [review]
Fix nth index cache to work correctly when nth-child selectors are only applied to some elements of a child list.
Attachment #542219 - Flags: review?(dbaron)
Created attachment 542224 [details] [diff] [review]
Merged to
Attachment #542224 - Flags: review?(dbaron)
Comment on attachment 542224 [details] [diff] [review]
Merged to

Wrong bug.
Attachment #542224 - Flags: review?(dbaron)
Whiteboard: [need review]
Attachment #542224 - Attachment is obsolete: true
Comment on attachment 542219 [details] [diff] [review]
Fix nth index cache to work correctly when nth-child selectors are only applied to some elements of a child list.

r=dbaron
Attachment #542219 - Flags: review?(dbaron) → review+
OS: Other → All
http://hg.mozilla.org/integration/mozilla-inbound/rev/5af231e7a58b
Flags: in-testsuite+
Whiteboard: [need review]
Target Milestone: --- → mozilla7
Comment on attachment 542219 [details] [diff] [review]
Fix nth index cache to work correctly when nth-child selectors are only applied to some elements of a child list.

Requesting approval to land this on aurora.  This fixes a regression in querySelector handling of the various nth-child and nth-of-type selectors (as well as handling of actual selector matching in some cases) that we unfortunately shipped in Firefox 5.  The fix is very very safe, and the old code is clearly wrong....
Attachment #542219 - Flags: approval-mozilla-aurora?
Comment on attachment 542219 [details] [diff] [review]
Fix nth index cache to work correctly when nth-child selectors are only applied to some elements of a child list.

approved for aurora (in triage meeting)
Attachment #542219 - Flags: approval-mozilla-aurora? → approval-mozilla-aurora+
http://hg.mozilla.org/releases/mozilla-aurora/rev/d8b00ee31575

Brian, thank you for reporting this!  The fix will ship in Firefox 6 in about 7 weeks.
status-firefox5: --- → affected
status-firefox6: --- → fixed
http://hg.mozilla.org/mozilla-central/rev/5af231e7a58b
Status: NEW → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → FIXED
(Reporter)

Comment 11

6 years ago
Thanks guys.

Updated

6 years ago
tracking-firefox6: ? → +
tracking-firefox7: ? → ---
Mozilla/5.0 (X11; Linux x86_64; rv:6.0) Gecko/20100101 Firefox/6.0
Mozilla/5.0 (X11; Linux x86_64; rv:7.0a2) Gecko/20110811 Firefox/7.0a2
Mozilla/5.0 (X11; Linux x86_64; rv:8.0a1) Gecko/20110807 Firefox/8.0a1

Verified on Ubuntu 11.04, MAC OS X 10.6, Windows 7, Windows XP with the attachment test case from the description. The results are now the same as other browsers (Opera, Chrome). The initial incorrect results on Firefox are no longer reproducible.

Setting status to verified Fixed.
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.