]> source.dussan.org Git - jquery.git/commitdiff
Make sure that .find() with multiple direct child selectors is handled correctly...
authorJohn Resig <jeresig@gmail.com>
Tue, 12 Oct 2010 13:19:49 +0000 (09:19 -0400)
committerJohn Resig <jeresig@gmail.com>
Tue, 12 Oct 2010 13:19:49 +0000 (09:19 -0400)
src/traversing.js
test/unit/traversing.js

index 5a479f2efc47825670905bbbfaaa4c7af3b2d130..968aab03674b6e48ca5afb04bb8846ba68896f7b 100644 (file)
@@ -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,
        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;
index f9e79372a761cc2196a04023a9399680b211925e..3332f077c4753824278f5828a6c328171a38ca54 100644 (file)
@@ -1,7 +1,7 @@
 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
@@ -9,6 +9,7 @@ test("find(String)", function() {
        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() {