Skip to main content

Bug Tracker

Side navigation

#2070 closed bug (fixed)

Opened December 17, 2007 07:00PM UTC

Closed December 17, 2007 09:07PM UTC

Last modified December 17, 2007 09:13PM UTC

not() fails to filter out <SELECT> DOM element (1.2.2b)

Reported by: joern Owned by:
Priority: major Milestone: 1.2.2
Component: core Version: 1.2.1
Keywords: Cc:
Blocked by: Blocking:
Description

not() fails to filter out a single DOM element. Test:

Index: test/unit/core.js
===================================================================
--- test/unit/core.js	(revision 4206)
+++ test/unit/core.js	(working copy)
@@ -1058,7 +1058,7 @@
 });
 
 test("not()", function() {
-	expect(7);
+	expect(8);
 	ok( $("#main > p#ap > a").not("#google").length == 2, "not('selector')" );
 	ok( $("#main > p#ap > a").not(document.getElementById("google")).length == 2, "not(DOMElement)" );
 	isSet( $("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" );
@@ -1066,6 +1066,9 @@
 	isSet( $("p").not($("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );
 	ok( $("p").not(document.getElementsByTagName("p")).length == 0, "not(Array-like DOM collection)" );
 	isSet( $("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d" ), "not('complex selector')");
+	
+	var selects = $("#form select");
+	isSet( selects.not( selects[1] ), ["select1", "select3"], "filter out DOM element");
 });
 
 test("andSelf()", function() {

Most likely the optimization in not() caused this to regress:

return this.filter(function() {
	// check to see if the selector is array-like otherwise assume it is just a DOM element
	return ( selector.length && selector[selector.length - 1] !== undefined )
		? jQuery.inArray( this, selector ) < 0
		: this != selector;
Attachments (0)
Change History (4)

Changed December 17, 2007 07:53PM UTC by davidserduke comment:1

resolution: → duplicate
status: newclosed

This should be fixed now in [4206]. Duplicate of #2062. Looks like you were writing this ticket while I was fixing it. :)

Changed December 17, 2007 08:29PM UTC by brandon comment:2

resolution: duplicate
status: closedreopened

Looks like the test Joern checked in for this ticket is still failing though.

Changed December 17, 2007 09:07PM UTC by davidserduke comment:3

resolution: → fixed
status: reopenedclosed
summary: not() fails to filter out DOM element (1.2.2b)not() fails to filter out <SELECT> DOM element (1.2.2b)

There were actually two issues. First the test case had an error and was supposed to use the q() function instead of an array [].

The second was the code saw <select> as array-like since it is and keeps its options in an array-like manner. So the code was doing not() on the options inside the select. I added a !nodeType to the array-like check so it won't iterate through array-like objects that are actually DOM elements.

It appears that fixes this issue.

Changed December 17, 2007 09:13PM UTC by davidserduke comment:4

Fixed in [4212].