From 2a0c7d702b83a6b2e40eb79a5d6ea94d74f3090d Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Wed, 17 Nov 2010 00:59:24 -0600 Subject: [PATCH] Coerce s.url to string before calling replace, since replace is also a method of a Location object. Fixes #7531. --- src/ajax.js | 5 ++++- test/unit/ajax.js | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/ajax.js b/src/ajax.js index d10b931..61b9c43 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -198,7 +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.toString().replace( rhash, "" ); // Use original (not extended) context object if it was provided s.context = origSettings && origSettings.context != null ? origSettings.context : s; diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 4ce14c2..b0c399b 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -1350,6 +1350,16 @@ test("jQuery.ajax - active counter", function() { 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" ); +}); } -- 1.7.10.4