Skip to main content

Bug Tracker

Side navigation

#6443 closed bug (wontfix)

Opened April 15, 2010 01:09PM UTC

Closed July 12, 2011 04:33PM UTC

Last modified March 13, 2012 08:54PM UTC

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 April 15, 2010 01:09PM UTC.
  • test2.html (2.3 KB) - added by rsinton April 15, 2010 08:41PM UTC.
Change History (7)

Changed April 15, 2010 07:40PM UTC by rsinton comment:1

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

Changed April 15, 2010 08:41PM UTC by rsinton comment:2

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 April 16, 2010 11:38AM UTC by rsinton comment:3

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'

Changed November 12, 2010 02:40AM UTC by snover comment:4

milestone: 1.4.3

Resetting milestone to future.

Changed November 20, 2010 08:50PM UTC by snover comment:5

milestone: → 1.4.5
priority: → high
status: newopen
version: 1.4.21.4.4

Changed January 12, 2011 07:43PM UTC by ctlajoie comment:6

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.

Changed July 12, 2011 04:33PM UTC by john comment:7

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