From b20eab42cdcf8d66f884f6da04cf5f241b78f3f5 Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Tue, 12 Sep 2017 11:24:45 -0400 Subject: [PATCH 1/2] Ajax: Don't process data property on no-entity-body requests Fixes gh-3438 --- src/ajax.js | 4 ++-- test/unit/ajax.js | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/ajax.js b/src/ajax.js index 27e533955c..45e41170b8 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -596,8 +596,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 ) { cacheURL += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data; // #9682: remove data so that it's not used in an eventual retry diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 4dc7b9d3a6..f49c26f192 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -1273,7 +1273,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" }, @@ -1288,6 +1288,21 @@ 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 + }; + } ); + var ifModifiedNow = new Date(); jQuery.each( From ee1a4d93227a40cfb7be1bffbba3e71378a6fa96 Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Mon, 23 Oct 2017 11:20:22 -0400 Subject: [PATCH 2/2] Add check for data being a string, per team meeting discussion --- src/ajax.js | 2 +- test/unit/ajax.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/ajax.js b/src/ajax.js index 45e41170b8..fcb72a95f5 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -597,7 +597,7 @@ jQuery.extend( { uncached = s.url.slice( cacheURL.length ); // If data is available and should be processed, append data to url - if ( s.data && s.processData ) { + 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 diff --git a/test/unit/ajax.js b/test/unit/ajax.js index f49c26f192..414a73f2eb 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -1303,6 +1303,22 @@ QUnit.module( "ajax", { }; } ); + 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(