Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit065143c

Browse files
wenzgibson042mgol
committed
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".Fixesgh-4119Closesgh-4650(cherry picked from7fb90a6)Co-authored-by: Richard Gibson <richard.gibson@gmail.com>Co-authored-by: Michał Gołębiowski-Owczarek <m.goleb@gmail.com>
1 parent1a4f10d commit065143c

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

‎src/ajax.js‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,5 +855,14 @@ jQuery.each( [ "get", "post" ], function( _i, method ) {
855855
};
856856
});
857857

858+
jQuery.ajaxPrefilter(function(s){
859+
vari;
860+
for(iins.headers){
861+
if(i.toLowerCase()==="content-type"){
862+
s.contentType=s.headers[i]||"";
863+
}
864+
}
865+
});
866+
858867
returnjQuery;
859868
});

‎test/unit/ajax.js‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,52 @@ QUnit.module( "ajax", {
13261326
};
13271327
});
13281328

1329+
ajaxTest("jQuery.ajax() - don't escape %20 with contentType override (gh-4119)",1,function(assert){
1330+
return{
1331+
url:"bogus.html",
1332+
contentType:"application/x-www-form-urlencoded",
1333+
headers:{"content-type":"application/json"},
1334+
method:"post",
1335+
dataType:"json",
1336+
data:"{\"val\":\"%20\"}",
1337+
beforeSend:function(_,s){
1338+
assert.strictEqual(s.data,"{\"val\":\"%20\"}","data is not %20-encoded");
1339+
returnfalse;
1340+
},
1341+
error:true
1342+
};
1343+
});
1344+
1345+
ajaxTest("jQuery.ajax() - escape %20 with contentType override (gh-4119)",1,function(assert){
1346+
return{
1347+
url:"bogus.html",
1348+
contentType:"application/json",
1349+
headers:{"content-type":"application/x-www-form-urlencoded"},
1350+
method:"post",
1351+
dataType:"json",
1352+
data:"{\"val\":\"%20\"}",
1353+
beforeSend:function(_,s){
1354+
assert.strictEqual(s.data,"{\"val\":\"+\"}","data is %20-encoded");
1355+
returnfalse;
1356+
},
1357+
error:true
1358+
};
1359+
});
1360+
1361+
ajaxTest("jQuery.ajax() - override contentType with header (gh-4119)",1,function(assert){
1362+
return{
1363+
url:"bogus.html",
1364+
contentType:"application/json",
1365+
headers:{"content-type":"application/x-www-form-urlencoded"},
1366+
beforeSend:function(_,s){
1367+
assert.strictEqual(s.contentType,"application/x-www-form-urlencoded",
1368+
"contentType is overwritten");
1369+
returnfalse;
1370+
},
1371+
error:true
1372+
};
1373+
});
1374+
13291375
ajaxTest("jQuery.ajax() - data - no processing POST",1,function(assert){
13301376
return{
13311377
url:"bogus.html",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp