Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Ajax: Don't process non-string data property on no-entity-body requests
Fixes gh-3438
Closes gh-3781
  • Loading branch information
dmethvin committed Jan 16, 2018
1 parent 022b69a commit d723789
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/ajax.js
Expand Up @@ -597,8 +597,8 @@ jQuery.extend( {
// Remember the hash so we can put it back
uncached = s.url.slice( cacheURL.length );

// If data is available, append data to url
if ( s.data ) {
// If data is available and should be processed, append data to url
if ( s.data && ( s.processData || typeof s.data === "string" ) ) {
cacheURL += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data;

// #9682: remove data so that it's not used in an eventual retry
Expand Down
33 changes: 32 additions & 1 deletion test/unit/ajax.js
Expand Up @@ -1274,7 +1274,7 @@ QUnit.module( "ajax", {
};
} );

ajaxTest( "jQuery.ajax() - data - no processing ", 1, function( assert ) {
ajaxTest( "jQuery.ajax() - data - no processing POST", 1, function( assert ) {
return {
url: "bogus.html",
data: { devo: "A Beautiful World" },
Expand All @@ -1289,6 +1289,37 @@ QUnit.module( "ajax", {
};
} );

ajaxTest( "jQuery.ajax() - data - no processing GET", 1, function( assert ) {
return {
url: "bogus.html",
data: { devo: "A Beautiful World" },
type: "get",
contentType: "x-something-else",
processData: false,
beforeSend: function( _, s ) {
assert.deepEqual( s.data, { devo: "A Beautiful World" }, "data is not processed" );
return false;
},
error: true
};
} );

ajaxTest( "jQuery.ajax() - data - process string with GET", 2, function( assert ) {
return {
url: "bogus.html",
data: "a=1&b=2",
type: "get",
contentType: "x-something-else",
processData: false,
beforeSend: function( _, s ) {
assert.equal( s.url, "bogus.html?a=1&b=2", "added data to url" );
assert.equal( s.data, undefined, "removed data from settings" );
return false;
},
error: true
};
} );

var ifModifiedNow = new Date();

jQuery.each(
Expand Down

0 comments on commit d723789

Please sign in to comment.