Skip to content

Conversation

@vanderlee
Copy link
Contributor

Inconsistent ehaviour for non-element nodes when using multiple recursive pseudo-selectors on * in .not() and .filter().

Fixes gh-2808

@mention-bot
Copy link

By analyzing the blame information on this pull request, we identified @gibson042, @timmywil and @markelog to be potential reviewers

@jquerybot
Copy link

Thank you for your pull request. It looks like this may be your first contribution to a jQuery Foundation project, if so we need you to sign our Contributor License Agreement (CLA).

📝 Please visit http://contribute.jquery.org/CLA/ to sign.

After you signed, the PR is checked again automatically after a minute. If there's still an issue, please reply here to let us know.


If you've already signed our CLA, it's possible your git author information doesn't match your CLA signature (both your name and email have to match), for more information, check the status of your CLA check.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the cheaper check should be evaled first

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be a cheaper check on it's own, but it's a far less discriminating check in most use cases as it would only ever be false when using non-element nodes.

As far as I know, only the .contents() function can return non-element nodes, so not a very common situation.

Placing the nodeType check last would shortcut it in most cases.

Placing the nodeType check first would mean both checks would have to be evaluated in most cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, the nodeType check is pretty rarely going to fail so the order isn't too important here.

Inconsistent ehaviour for non-element nodes when using multiple recursive pseudo-selectors on `*` in `.not()` and `.filter()`.
@gibson042
Copy link
Member

The code change looks good, but it needs jQuery.filter and/or jQuery.not unit tests backing it up.

@vanderlee
Copy link
Contributor Author

Unittests should be simple enough.
I'll look into it somewhere today or tomorrow.

@vanderlee
Copy link
Contributor Author

Added two unittests which cover the issue.
They both fail without the fix, but work with the fix.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you combine these tests together into something like "not(Selector) excludes non-element nodes (gh-2808)", and use simpler selectors? E.g.,

var mixedContents = jQuery( "#nonnodes" ).contents(),
    childElements = q( "nonnodesElement" );
assert.deepEqual( mixedContents.not( "*" ).get(), [], "not *" );
assert.deepEqual( mixedContents.not( "[id=a],[id=b]" ).get(), childElements, "not [id=a],[id=b]" );
assert.deepEqual( mixedContents.not( "[id=a],*,[id=b]" ).get(), [], "not [id=a],*,[id=b]" );

(https://github.com/vanderlee/jquery/blob/patch-1/test/index.html#L210)

@timmywil timmywil closed this in 0e2f8f9 Jan 13, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

6 participants