Commit f9f9ee52 authored by John Resig's avatar John Resig

Make sure that #... are trimmed from Ajax request URLs. Fixes #4987.

parent a32f4d7b
...@@ -10,6 +10,7 @@ var jsc = jQuery.now(), ...@@ -10,6 +10,7 @@ var jsc = jQuery.now(),
rts = /([?&])_=[^&]*(&?)/, rts = /([?&])_=[^&]*(&?)/,
rurl = /^(\w+:)?\/\/([^\/?#]+)/, rurl = /^(\w+:)?\/\/([^\/?#]+)/,
r20 = /%20/g, r20 = /%20/g,
rhash = /#[^#]*$/,
// Keep a copy of the old load method // Keep a copy of the old load method
_load = jQuery.fn.load; _load = jQuery.fn.load;
...@@ -205,6 +206,7 @@ jQuery.extend({ ...@@ -205,6 +206,7 @@ jQuery.extend({
var s = jQuery.extend(true, {}, jQuery.ajaxSettings, origSettings), var s = jQuery.extend(true, {}, jQuery.ajaxSettings, origSettings),
jsonp, status, data, type = s.type.toUpperCase(); jsonp, status, data, type = s.type.toUpperCase();
s.url = s.url.replace( rhash, "" );
s.context = origSettings && origSettings.context || s; s.context = origSettings && origSettings.context || s;
// convert data if not already a string // convert data if not already a string
......
...@@ -68,6 +68,35 @@ test("jQuery.ajax() - error callbacks", function() { ...@@ -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() { test(".ajax() - 304", function() {
expect( 1 ); expect( 1 );
stop(); stop();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment