Bug Tracker

Opened 13 years ago

Closed 12 years ago

Last modified 11 years ago

#6443 closed bug (wontfix)

Some multi stage sibling selectors delivering different results in jQuery 1.4 vs 1.3

Reported by: rsinton Owned by:
Priority: high Milestone: 1.next
Component: selector Version: 1.4.4
Keywords: sibling selector contains Cc:
Blocked by: Blocking:

Description

Some selectors, such as

$( '#one ~ #two span:contains(word)' )

and

$( '#one + #two span:visible' )

are giving me the results I expect in 1.3, but not in 1.4

Reduced case attached, with similar selectors that work as expected for comparison, e.g.

$( '#one ~ #two span:last' )

is fine.

Seems to only be for (pardon my invented terminology) some qualifed ancestors following sibling selection ( ~ or + ).

Verified in Safari 4.0.4 and Firefox 3.5.9. Tried with jQuery 1.4.2 and nightly build 1.4.3pre 28 Feb 2010.

Attachments (2)

test.html (2.0 KB) - added by rsinton 13 years ago.
test2.html (2.3 KB) - added by rsinton 13 years ago.

Download all attachments as: .zip

Change History (9)

Changed 13 years ago by rsinton

Attachment: test.html added

comment:1 Changed 13 years ago by rsinton

That should of course read "qualified *descendants* of selected siblings".

comment:2 Changed 13 years ago by rsinton

Some code scrounging, head-scratching, and testing points to the shortcut at line 2694 (1.4.2) with the heading: "Take a shortcut and set the context if the root selector is an ID". Disabling this removes the problem.

Extra test cases G2 and G3 in test2.html also show that the problem goes away if the root selector is a class selector rather than ID selector.

Changed 13 years ago by rsinton

Attachment: test2.html added

comment:3 Changed 13 years ago by rsinton

Actually, the more I look at it, the more I think the fix is just to disqualify sibling selectors for that shortcut (middle line added):

if ( !seed && parts.length > 1 && context.nodeType === 9 && !contextXML && !parts[1] === "~" && !parts[1] === "+" && Expr.match.ID.test(parts[0]) && !Expr.match.ID.test(parts[parts.length - 1]) ) {

The reason being that the LHS of 'a b' or 'a > b' is the same thing as a context for the RHS, but that's not true for 'a ~ b' or 'a + b'

comment:4 Changed 12 years ago by snover

Milestone: 1.4.3

Resetting milestone to future.

comment:5 Changed 12 years ago by snover

Milestone: 1.4.5
Priority: high
Status: newopen
Version: 1.4.21.4.4

comment:6 Changed 12 years ago by ctlajoie

I added another test case to snover's set linked above.
It involves a regression that started with 1.4.3 involving sibling selectors passed to the find function.
For example: $('#one').find('~ #two')
It works for jQuery 1.3.2 and 1.4.2, but fails in 1.4.3 and 1.4.4.

I considered adding a new ticket for this but decided to just comment here. If it seems different enough to you guys you can make a new ticket.

comment:7 Changed 12 years ago by john

Resolution: wontfix
Status: openclosed

Unfortunately this isn't something that we're going to be able to fix in the current incarnation of the Sizzle engine. We hope to fix this in the near future. http://docs.jquery.com/Won%27t_Fix

Note: See TracTickets for help on using tickets.