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

Commit7fb90a6

Browse files
wenzgibson042mgol
authored
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-4650Co-authored-by: Richard Gibson <richard.gibson@gmail.com>Co-authored-by: Michał Gołębiowski-Owczarek <m.goleb@gmail.com>
1 parent90fed4b commit7fb90a6

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
@@ -861,4 +861,13 @@ jQuery.each( [ "get", "post" ], function( _i, method ) {
861861
};
862862
});
863863

864+
jQuery.ajaxPrefilter(function(s){
865+
vari;
866+
for(iins.headers){
867+
if(i.toLowerCase()==="content-type"){
868+
s.contentType=s.headers[i]||"";
869+
}
870+
}
871+
});
872+
864873
exportdefaultjQuery;

‎test/unit/ajax.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,52 @@ QUnit.module( "ajax", {
14101410
};
14111411
});
14121412

1413+
ajaxTest("jQuery.ajax() - don't escape %20 with contentType override (gh-4119)",1,function(assert){
1414+
return{
1415+
url:"bogus.html",
1416+
contentType:"application/x-www-form-urlencoded",
1417+
headers:{"content-type":"application/json"},
1418+
method:"post",
1419+
dataType:"json",
1420+
data:"{\"val\":\"%20\"}",
1421+
beforeSend:function(_,s){
1422+
assert.strictEqual(s.data,"{\"val\":\"%20\"}","data is not %20-encoded");
1423+
returnfalse;
1424+
},
1425+
error:true
1426+
};
1427+
});
1428+
1429+
ajaxTest("jQuery.ajax() - escape %20 with contentType override (gh-4119)",1,function(assert){
1430+
return{
1431+
url:"bogus.html",
1432+
contentType:"application/json",
1433+
headers:{"content-type":"application/x-www-form-urlencoded"},
1434+
method:"post",
1435+
dataType:"json",
1436+
data:"{\"val\":\"%20\"}",
1437+
beforeSend:function(_,s){
1438+
assert.strictEqual(s.data,"{\"val\":\"+\"}","data is %20-encoded");
1439+
returnfalse;
1440+
},
1441+
error:true
1442+
};
1443+
});
1444+
1445+
ajaxTest("jQuery.ajax() - override contentType with header (gh-4119)",1,function(assert){
1446+
return{
1447+
url:"bogus.html",
1448+
contentType:"application/json",
1449+
headers:{"content-type":"application/x-www-form-urlencoded"},
1450+
beforeSend:function(_,s){
1451+
assert.strictEqual(s.contentType,"application/x-www-form-urlencoded",
1452+
"contentType is overwritten");
1453+
returnfalse;
1454+
},
1455+
error:true
1456+
};
1457+
});
1458+
14131459
ajaxTest("jQuery.ajax() - data - no processing POST",1,function(assert){
14141460
return{
14151461
url:"bogus.html",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp