Skip to content

Commit

Permalink
Fixes #8310. Make sure that sibling selectors (+,~) in some edge case…
Browse files Browse the repository at this point in the history
…s don't leave modification behind in the DOM.

Follow up to 8b34687 which caused Sizzle to sometimes
leave modifications behind in the DOM and remove the id attribute on the wrong element.
  • Loading branch information
jitter committed Feb 18, 2011
1 parent ab88b45 commit ef19279
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions sizzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,8 @@ if ( document.querySelectorAll ) {
// and working up from there (Thanks to Andrew Dupont for the technique)
// IE 8 doesn't work on object elements
} else if ( context.nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
var old = context.getAttribute( "id" ),
var oldContext = context,
old = context.getAttribute( "id" ),
nid = old || id,
hasParent = context.parentNode,
relativeHierarchySelector = /^\s*[+~]/.test( query );
Expand All @@ -1179,7 +1180,7 @@ if ( document.querySelectorAll ) {
} catch(pseudoError) {
} finally {
if ( !old ) {
context.removeAttribute( "id" );
oldContext.removeAttribute( "id" );
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion test/unit/selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ test("multiple", function() {
});

test("child and adjacent", function() {
expect(29);
expect(33);
t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
Expand All @@ -253,6 +253,11 @@ test("child and adjacent", function() {
same( jQuery("#siblingfirst").find("~ em").get(), q("siblingnext"), "Element Preceded By with a context." );
same( jQuery("#siblingfirst").find("+ em").get(), q("siblingnext"), "Element Directly Preceded By with a context." );

equal( jQuery("#listWithTabIndex").length, 1, "Parent div for next test is found via ID (#8310)" );
equal( jQuery("#listWithTabIndex li:eq(2) ~ li").length, 1, "Find by general sibling combinator (#8310)" );
equal( jQuery("#__sizzle__").length, 0, "Make sure the temporary id assigned by sizzle is cleared out (#8310)" );
equal( jQuery("#listWithTabIndex").length, 1, "Parent div for previous test is still found via ID (#8310)" );

t( "Verify deep class selector", "div.blah > p > a", [] );

t( "No element deep selector", "div.foo > span > a", [] );
Expand Down

0 comments on commit ef19279

Please sign in to comment.