Bug Tracker

Opened 10 years ago

Closed 9 years ago

Last modified 8 years ago

#4999 closed bug (fixed)

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/

Change History (5)

comment:1 Changed 10 years ago by glyphobet

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."

comment:2 Changed 10 years ago by glyphobet

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.

comment:3 Changed 10 years ago by glyphobet

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.

comment:4 Changed 10 years ago by glyphobet

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.

comment:5 Changed 9 years ago by dmethvin

Resolution: fixed
Status: newclosed

This was fixed in jQuery 1.4.

Note: See TracTickets for help on using tickets.