aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorChristian Wenz <christian@wenz.org>2020-04-06 21:15:55 +0200
committerGitHub <noreply@github.com>2020-04-06 21:15:55 +0200
commit7fb90a6beaeffe16699800f73746748f6a5cc2de (patch)
tree7236b990a72a361020ced04f24492b0171444dee /test
parent90fed4b453a5becdb7f173d9e3c1492390a1441f (diff)
downloadjquery-7fb90a6beaeffe16699800f73746748f6a5cc2de.tar.gz
jquery-7fb90a6beaeffe16699800f73746748f6a5cc2de.zip
Ajax: Overwrite s.contentType with content-type header value, if any
This fixes the issue of "%20" in POST data being replaced with "+" even for requests with content-type different from "application/x-www-form-urlencoded", e.g. for "application/json". Fixes gh-4119 Closes gh-4650 Co-authored-by: Richard Gibson <richard.gibson@gmail.com> Co-authored-by: Michał Gołębiowski-Owczarek <m.goleb@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/unit/ajax.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/unit/ajax.js b/test/unit/ajax.js
index ed17677ba..e13c2713d 100644
--- a/test/unit/ajax.js
+++ b/test/unit/ajax.js
@@ -1410,6 +1410,52 @@ QUnit.module( "ajax", {
};
} );
+ ajaxTest( "jQuery.ajax() - don't escape %20 with contentType override (gh-4119)", 1, function( assert ) {
+ return {
+ url: "bogus.html",
+ contentType: "application/x-www-form-urlencoded",
+ headers: { "content-type": "application/json" },
+ method: "post",
+ dataType: "json",
+ data: "{\"val\":\"%20\"}",
+ beforeSend: function( _, s ) {
+ assert.strictEqual( s.data, "{\"val\":\"%20\"}", "data is not %20-encoded" );
+ return false;
+ },
+ error: true
+ };
+ } );
+
+ ajaxTest( "jQuery.ajax() - escape %20 with contentType override (gh-4119)", 1, function( assert ) {
+ return {
+ url: "bogus.html",
+ contentType: "application/json",
+ headers: { "content-type": "application/x-www-form-urlencoded" },
+ method: "post",
+ dataType: "json",
+ data: "{\"val\":\"%20\"}",
+ beforeSend: function( _, s ) {
+ assert.strictEqual( s.data, "{\"val\":\"+\"}", "data is %20-encoded" );
+ return false;
+ },
+ error: true
+ };
+ } );
+
+ ajaxTest( "jQuery.ajax() - override contentType with header (gh-4119)", 1, function( assert ) {
+ return {
+ url: "bogus.html",
+ contentType: "application/json",
+ headers: { "content-type": "application/x-www-form-urlencoded" },
+ beforeSend: function( _, s ) {
+ assert.strictEqual( s.contentType, "application/x-www-form-urlencoded",
+ "contentType is overwritten" );
+ return false;
+ },
+ error: true
+ };
+ } );
+
ajaxTest( "jQuery.ajax() - data - no processing POST", 1, function( assert ) {
return {
url: "bogus.html",