From f9f9ee52e16f37900296e06982a7dccba89c5a78 Mon Sep 17 00:00:00 2001 From: John Resig Date: Wed, 22 Sep 2010 12:52:44 -0400 Subject: [PATCH] Make sure that #... are trimmed from Ajax request URLs. Fixes #4987. --- src/ajax.js | 2 ++ test/unit/ajax.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/ajax.js b/src/ajax.js index cc87133..97d4039 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -10,6 +10,7 @@ var jsc = jQuery.now(), rts = /([?&])_=[^&]*(&?)/, rurl = /^(\w+:)?\/\/([^\/?#]+)/, r20 = /%20/g, + rhash = /#[^#]*$/, // Keep a copy of the old load method _load = jQuery.fn.load; @@ -205,6 +206,7 @@ jQuery.extend({ var s = jQuery.extend(true, {}, jQuery.ajaxSettings, origSettings), jsonp, status, data, type = s.type.toUpperCase(); + s.url = s.url.replace( rhash, "" ); s.context = origSettings && origSettings.context || s; // convert data if not already a string diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 7f3f39a..b7eb57d 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -68,6 +68,35 @@ test("jQuery.ajax() - error callbacks", function() { }); }); +test(".ajax() - hash", function() { + expect(3); + + jQuery.ajax({ + url: "data/name.html#foo", + beforeSend: function( xhr, settings ) { + equals(settings.url, "data/name.html", "Make sure that the URL is trimmed."); + return false; + } + }); + + jQuery.ajax({ + url: "data/name.html?abc#foo", + beforeSend: function( xhr, settings ) { + equals(settings.url, "data/name.html?abc", "Make sure that the URL is trimmed."); + return false; + } + }); + + jQuery.ajax({ + url: "data/name.html?abc#foo", + data: { "test": 123 }, + beforeSend: function( xhr, settings ) { + equals(settings.url, "data/name.html?abc&test=123", "Make sure that the URL is trimmed."); + return false; + } + }); +}); + test(".ajax() - 304", function() { expect( 1 ); stop(); -- 1.7.10.4