Skip to content

Commit

Permalink
Fixes #7369 - Using an attribute selector for a non-existent attribut…
Browse files Browse the repository at this point in the history
…e raised an exception on disconnected nodes
  • Loading branch information
timmywil committed Mar 31, 2011
1 parent 6c28a39 commit a807451
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/traversing.js
Expand Up @@ -112,7 +112,7 @@ jQuery.fn.extend({

} else {
cur = cur.parentNode;
if ( !cur || !cur.ownerDocument || cur === context ) {
if ( !cur || !cur.ownerDocument || cur === context || cur.nodeType === 11 ) {
break;
}
}
Expand Down
6 changes: 5 additions & 1 deletion test/unit/traversing.js
Expand Up @@ -124,7 +124,7 @@ test("filter(jQuery)", function() {
})

test("closest()", function() {
expect(11);
expect(13);
same( jQuery("body").closest("body").get(), q("body"), "closest(body)" );
same( jQuery("body").closest("html").get(), q("html"), "closest(html)" );
same( jQuery("body").closest("div").get(), [], "closest(div)" );
Expand All @@ -144,6 +144,10 @@ test("closest()", function() {

// Test on disconnected node
equals( jQuery("<div><p></p></div>").find("p").closest("table").length, 0, "Make sure disconnected closest work." );

// Bug #7369
equals( jQuery('<div foo="bar"></div>').closest('[foo]').length, 1, "Disconnected nodes with attribute selector" );
equals( jQuery('<div>text</div>').closest('[lang]').length, 0, "Disconnected nodes with text and non-existent attribute selector" );
});

test("closest(Array)", function() {
Expand Down

0 comments on commit a807451

Please sign in to comment.