]> source.dussan.org Git - jquery.git/commitdiff
Ajax: Allow `processData: true` even for binary data
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>
Mon, 20 Mar 2023 16:08:51 +0000 (17:08 +0100)
committerGitHub <noreply@github.com>
Mon, 20 Mar 2023 16:08:51 +0000 (17:08 +0100)
The way gh-5197 implemented binary data handling, `processData`
was being explicitly set to `false`. This is expected but it made
it impossible to override it to `true`. The new logic will only
set `processData` to `false` if it wasn't explicitly passed
in original options.

Closes gh-5205
Ref gh-5197

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

index e96661da779adcd27fc8e0cd8ea403c300b6212f..16f06d7e9ec6e179658851c543432fb8e5e02def 100644 (file)
@@ -2,10 +2,13 @@ import jQuery from "../core.js";
 
 import "../ajax.js";
 
-jQuery.ajaxPrefilter( function( s ) {
+jQuery.ajaxPrefilter( function( s, origOptions ) {
 
        // Binary data needs to be passed to XHR as-is without stringification.
-       if ( typeof s.data !== "string" && !jQuery.isPlainObject( s.data ) ) {
+       if ( typeof s.data !== "string" && !jQuery.isPlainObject( s.data ) &&
+
+                       // Don't disable data processing if explicitly set by the user.
+                       !( "processData" in origOptions ) ) {
                s.processData = false;
        }
 
index 7ecedc212196ce2dba206e688ef663284535bda6..bcaa7651d499bbb5a29d044fb255ac677aa5e2e7 100644 (file)
@@ -3148,4 +3148,27 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
                };
        } );
 
+       ajaxTest( "jQuery.ajax() - non-plain object", 1, function( assert ) {
+               return {
+                       url: url( "mock.php?action=name" ),
+                       method: "post",
+                       data: Object.create( { name: "peter" } ),
+                       success: function( data ) {
+                               assert.strictEqual( data, "ERROR", "Data correctly not sent" );
+                       }
+               };
+       } );
+
+       ajaxTest( "jQuery.ajax() - non-plain object with processData: true", 1, function( assert ) {
+               return {
+                       url: url( "mock.php?action=name" ),
+                       method: "post",
+                       processData: true,
+                       data: Object.create( { name: "peter" } ),
+                       success: function( data ) {
+                               assert.strictEqual( data, "pan", "Data sent correctly" );
+                       }
+               };
+       } );
+
 } )();