Permalink
Browse files

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

  • Loading branch information...
jeresig committed Sep 22, 2010
1 parent a32f4d7 commit f9f9ee52e16f37900296e06982a7dccba89c5a78
Showing with 31 additions and 0 deletions.
  1. +2 −0 src/ajax.js
  2. +29 −0 test/unit/ajax.js
@@ -10,6 +10,7 @@ var jsc = jQuery.now(),
rts = /([?&])_=[^&]*(&?)/,
rurl = /^(\w+:)?\/\/([^\/?#]+)/,
r20 = /%20/g,
rhash = /#[^#]*$/,

This comment has been minimized.

@aivopaas

aivopaas Sep 22, 2010

What about "dir/file.html#foo#bar"?
Shouldn't it be /#.*$/ just to be sure?

This comment has been minimized.

@jeresig

jeresig Sep 22, 2010

Author Member

Hmm yeah - fixed. ab454d9


// 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, "" );

This comment has been minimized.

@jdalton

jdalton Sep 23, 2010

Member

I think I have split() that jazz before. s.url.split('#')[0]

s.context = origSettings && origSettings.context || s;

// convert data if not already a string
@@ -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();

0 comments on commit f9f9ee5

Please sign in to comment.