Permalink
Browse files

Make sure that .find() with multiple direct child selectors is handle…

…d correctly. Fixes #7144.
  • Loading branch information...
1 parent ff6cead commit 5200194f517a7bde7bbe9aa50dc1e81f1e1db441 @jeresig jeresig committed Oct 12, 2010
Showing with 4 additions and 3 deletions.
  1. +2 −2 src/traversing.js
  2. +2 −1 test/unit/traversing.js
View
@@ -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,
@davidmurdoch

davidmurdoch Oct 12, 2010

Contributor

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.

@jeresig

jeresig Oct 12, 2010

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;
@@ -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;
View
@@ -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() {

0 comments on commit 5200194

Please sign in to comment.