Index: misc/ajax.js
===================================================================
RCS file: /cvs/drupal/drupal/misc/ajax.js,v
retrieving revision 1.19
diff -u -p -r1.19 ajax.js
--- misc/ajax.js	22 Sep 2010 21:01:39 -0000	1.19
+++ misc/ajax.js	22 Sep 2010 23:50:25 -0000
@@ -173,7 +173,7 @@ Drupal.ajax = function (base, element, e
           ajax.form.clk = this.element;
         }
 
-        ajax.form.ajaxSubmit(options);     
+        ajax.form.ajaxSubmit(options);
       }
       else {
         $.ajax(options);
@@ -354,9 +354,16 @@ 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);
+    // Do not use $() directly on long strings because Safari can crash.
+    // However, don't bother with this method on shorter strings because
+    // there is no guarantee that what we want to replace is a div.
+    // See http://dev.jquery.com/ticket/3178
+    if (response.data.length > 49999) {
+      var new_content = $('<div></div>').html(response.data);
+    }
+    else {
+      var new_content = $(response.data);
+    }
 
     // If removing content from the wrapper, detach behaviors first.
     switch (method) {
