Merge branch 'bug7531' of https://github.com/csnover/jquery into csnover-bug7531
authorJohn Resig <jeresig@gmail.com>
Mon, 6 Dec 2010 22:22:02 +0000 (17:22 -0500)
committerJohn Resig <jeresig@gmail.com>
Mon, 6 Dec 2010 22:22:02 +0000 (17:22 -0500)
1  2 
src/ajax.js
test/unit/ajax.js

diff --combined src/ajax.js
@@@ -198,7 -198,10 +198,10 @@@ jQuery.extend(
                var s = jQuery.extend(true, {}, jQuery.ajaxSettings, origSettings),
                        jsonp, status, data, type = s.type.toUpperCase(), noContent = rnoContent.test(type);
  
-               s.url = s.url.replace( rhash, "" );
+               // toString fixes people passing a window.location or
+               // document.location to $.ajax, which worked in 1.4.2 and
+               // earlier (bug #7531). It should be removed in 1.5.
+               s.url = ("" + s.url).replace( rhash, "" );
  
                // Use original (not extended) context object if it was provided
                s.context = origSettings && origSettings.context != null ? origSettings.context : s;
                        };
                }
  
 -              if ( s.dataType === "script" && s.cache === null ) {
 +              if ( s.dataType === "script" && s.cache === undefined ) {
                        s.cache = false;
                }
  
diff --combined test/unit/ajax.js
@@@ -710,10 -710,10 +710,10 @@@ test("jQuery.getScript(String, Function
  });
  
  test("jQuery.ajax() - JSONP, Local", function() {
 -      expect(8);
 +      expect(9);
  
        var count = 0;
 -      function plus(){ if ( ++count == 8 ) start(); }
 +      function plus(){ if ( ++count == 9 ) start(); }
  
        stop();
  
                        plus();
                }
        });
 +
 +      //#7578
 +      jQuery.ajax({
 +              url: "data/jsonp.php",
 +              dataType: "jsonp",
 +              beforeSend: function(){
 +                      strictEqual( this.cache, false, "cache must be false on JSON request" );
 +                      plus();
 +                      return false;
 +              }
 +      });
  });
  
  test("JSONP - Custom JSONP Callback", function() {
@@@ -1361,6 -1350,16 +1361,16 @@@ test("jQuery.ajax - active counter", fu
      ok( jQuery.active == 0, "ajax active counter should be zero: " + jQuery.active );
  });
  
+ test( "jQuery.ajax - Location object as url (#7531)", 1, function () {
+       var success = false;
+       try {
+               var xhr = jQuery.ajax({ url: document.location });
+               success = true;
+               xhr.abort();
+       } catch (e) {}
+       ok( success, "document.location did not generate exception" );
+ });
  
  }