]> source.dussan.org Git - jquery.git/commitdiff
Ajax: Don't process non-string data property on no-entity-body requests
authorDave Methvin <dave.methvin@gmail.com>
Tue, 12 Sep 2017 15:24:45 +0000 (11:24 -0400)
committerDave Methvin <dave.methvin@gmail.com>
Tue, 16 Jan 2018 02:48:54 +0000 (21:48 -0500)
Fixes gh-3438
Closes gh-3781

src/ajax.js
test/unit/ajax.js

index dd13212407556f014958d22ede88ac731659705e..aec26830a2f3e24bf4546b9e5a52c7bed2b45acf 100644 (file)
@@ -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
index 26aa3ad214fc396d0f22ec99c917dc0d3fb02187..ab5ce24a8bc20bcde3d7b98d8aead6984504e1c2 100644 (file)
@@ -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" },
@@ -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(