Skip to main content

Bug Tracker

Side navigation

#4999 closed bug (fixed)

Opened August 01, 2009 06:54AM UTC

Closed November 19, 2010 12:50AM UTC

Last modified March 15, 2012 11:29AM UTC

Selectors with commas do not work in jQuery 1.3 and IE 7 against XHR documents

Reported by: glyphobet Owned by: john
Priority: major Milestone: 1.4
Component: selector Version: 1.3.2
Keywords: Cc: glyphobet
Blocked by: Blocking:
Description

jQuery 1.3 & Internet Explorer 7 do not correctly select from an XMLHttpRequest document.

Selecting multiple nodes by node name with a selector like "i, b" causes a JavaScript error. This problem is not present in jQuery 1.2. It is not present in Firefox 3.5 or Safari 4. This bug appears to have been reported already: http://osdir.com/ml/jQuery/2009-02/msg03487.html

I have written a test case for this bug: http://glyphobet.net/jquery-selector-bug/

Attachments (0)
Change History (5)

Changed August 11, 2009 05:51PM UTC by glyphobet comment:1

Discussion on the IRC channel confirms this bug is happening for other people. It also confirms that this bug is not present in Internet Explorer 8 running in Internet Explorer 7 developer mode, only in the real Internet Explorer 7.

The first JavaScript error is in jQuery, line 20, character 1335, "Error: Number expected." The second is in the JavaScript above, line 15, character 9: "Object doesn't support this property or method."

Changed August 13, 2009 02:30AM UTC by glyphobet comment:2

The problem is in the sortOrder function defined starting at line 2116:

sortOrder = function( a, b ) {

alert(a.sourceIndex - b.sourceIndex);

var ret = a.sourceIndex - b.sourceIndex;

if ( ret === 0 ) {

hasDuplicate = true;

}

return ret;

};

When a and b are elements from an XML DOM, they do not have sortOrder attributes. This function subtracts undefined from undefined, gets NaN, stores it in ret, and returns it. But the sort() function is expecting a number to be returned, hence the error.

Changed August 13, 2009 02:34AM UTC by glyphobet comment:3

Sorry, I should have said line 2108 in my previous comment.

If I comment out this entire sortOrder function and the if statement that creates it (2108-2116), the code falls back to the third sortOrder function, which uses createRange() and compareBoundaryPoints() to figure out the sort order. This sortOrder function appears to work properly.

Changed August 13, 2009 02:38AM UTC by glyphobet comment:4

In other words, this patch appears to fix the bug:

--- jquery.1.3.js.bak	2009-08-12 19:12:56.000000000 -0700
+++ jquery.1.3.js	2009-08-12 19:38:27.000000000 -0700
@@ -2104,14 +2104,6 @@
 		}
 		return ret;
 	};
-} else if ( "sourceIndex" in document.documentElement ) {
-	sortOrder = function( a, b ) {
-		var ret = a.sourceIndex - b.sourceIndex;
-		if ( ret === 0 ) {
-			hasDuplicate = true;
-		}
-		return ret;
-	};
 } else if ( document.createRange ) {
 	sortOrder = function( a, b ) {
 		var aRange = a.ownerDocument.createRange(), bRange = b.ownerDocument.createRange();

However, I do not know enough about jQuery to know whether removing this code has other adverse effects.

Changed November 19, 2010 12:50AM UTC by dmethvin comment:5

resolution: → fixed
status: newclosed

This was fixed in jQuery 1.4.