Skip to content

Commit

Permalink
Ajax: Allow processData: true even for binary data
Browse files Browse the repository at this point in the history
The way jquerygh-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.

Ref jquerygh-5197
  • Loading branch information
mgol committed Feb 8, 2023
1 parent 7e7bd06 commit b20fd39
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/ajax/binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
23 changes: 23 additions & 0 deletions test/unit/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
}
};
} );

} )();

0 comments on commit b20fd39

Please sign in to comment.