Skip to content

Commit

Permalink
Make sure that .find() with multiple direct child selectors is handle…
Browse files Browse the repository at this point in the history
…d correctly. Fixes #7144.
  • Loading branch information
jeresig committed Oct 12, 2010
1 parent ff6cead commit 5200194
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/traversing.js
Expand Up @@ -4,7 +4,7 @@ var runtil = /Until$/,
rparentsprev = /^(?:parents|prevUntil|prevAll)/,
// Note: This RegExp should be improved, or likely pulled from Sizzle
rmultiselector = /,/,
rchild = /^\s*>/,
rchild = /(^|,)\s*>/g,

This comment has been minimized.

Copy link
@davidmurdoch

davidmurdoch Oct 12, 2010

Why not just match selector strings that contain just one child (>) selector? Something like: /^\s*>([^>]*)$/? The > div > case is not nearly as common as > or > div.

This comment has been minimized.

Copy link
@jeresig

jeresig Oct 12, 2010

Author Member

What we care about is just that the selector begins with a >. We want to move to no longer supporting that in Sizzle (thus we would support it directly in jQuery). Although it seems like it'll definitely require more work on our end to get there. We'll definitely look into it in the future.

isSimple = /^.[^:#\[\.,]*$/,
slice = Array.prototype.slice,
POS = jQuery.expr.match.POS;
Expand All @@ -13,7 +13,7 @@ jQuery.fn.extend({
find: function( selector ) {
// Handle "> div" child selectors and pass them to .children()
if ( typeof selector === "string" && rchild.test( selector ) ) {
return this.children( selector.replace( rchild, "" ) );
return this.children( selector.replace( rchild, "$1" ) );
}

var ret = this.pushStack( "", "find", selector ), length = 0;
Expand Down
3 changes: 2 additions & 1 deletion test/unit/traversing.js
@@ -1,14 +1,15 @@
module("traversing");

test("find(String)", function() {
expect(3);
expect(4);
equals( 'Yahoo', jQuery('#foo').find('.blogTest').text(), 'Check for find' );

// using contents will get comments regular, text, and comment nodes
var j = jQuery("#nonnodes").contents();
equals( j.find("div").length, 0, "Check node,textnode,comment to find zero divs" );

same( jQuery("#main").find("> div").get(), q("foo", "moretests", "tabindex-tests", "liveHandlerOrder", "siblingTest"), "find child elements" );
same( jQuery("#main").find("> #foo, > #moretests").get(), q("foo", "moretests"), "find child elements" );
});

test("is(String)", function() {
Expand Down

0 comments on commit 5200194

Please sign in to comment.