Index: misc/ajax.js
===================================================================
RCS file: /cvs/drupal/drupal/misc/ajax.js,v
retrieving revision 1.17
diff -u -p -r1.17 ajax.js
--- misc/ajax.js	16 May 2010 19:08:08 -0000	1.17
+++ misc/ajax.js	14 Jun 2010 21:41:13 -0000
@@ -325,9 +325,20 @@ Drupal.ajax.prototype.commands = {
     var method = response.method || ajax.method;
     var effect = ajax.getEffect(response);
 
-    // Manually insert HTML into the jQuery object, using $() directly crashes
-    // Safari with long string lengths. http://dev.jquery.com/ticket/3178
-    var new_content = $('<div></div>').html(response.data);
+    var new_content = $(response.data);
+    // For legacy reasons, the effects processing code assumes that new_content
+    // consists of a single top-level element. Also, it has not been
+    // sufficiently tested whether attachBehaviors() can be successfully called
+    // with a context object that includes top-level text nodes. Therefore, add
+    // a container DIV element when the content is something other than a
+    // single top-level element. Developers needing full control of the HTML
+    // that is inserted, or inserting content where DIV elements are not
+    // allowed (e.g., within TABLE, TR, and SPAN parents), are encouraged to
+    // return content that is contained within a single top-level element. For
+    // more information, please see http://drupal.org/node/736066.
+    if (new_content.length != 1 || new_content.get(0).nodeType != 1) {
+      new_content = new_content.wrapAll('<div></div>');
+    }
 
     // If removing content from the wrapper, detach behaviors first.
     switch (method) {
