mirror of
https://github.com/tenrok/axios.git
synced 2026-06-11 18:02:32 +03:00
Fixed toFormData regression bug (unreleased) with Array-like objects serialization; (#4714)
Added `toURLEncodedForm` helper; Added automatic payload serialization to `application/x-www-form-urlencoded` to have parity with `multipart/form-data`; Added test of handling `application/x-www-form-urlencoded` body by express.js; Updated README.md; Added missed param in JSDoc; Fixed hrefs in README.md; Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (function getURLSearchParams(nativeURLSearchParams) {
|
||||
if (typeof nativeURLSearchParams === 'function') return nativeURLSearchParams;
|
||||
|
||||
function encode(str) {
|
||||
var charMap = {
|
||||
'!': '%21',
|
||||
"'": '%27',
|
||||
'(': '%28',
|
||||
')': '%29',
|
||||
'~': '%7E',
|
||||
'%20': '+',
|
||||
'%00': '\x00'
|
||||
};
|
||||
return encodeURIComponent(str).replace(/[!'\(\)~]|%20|%00/g, function replacer(match) {
|
||||
return charMap[match];
|
||||
});
|
||||
}
|
||||
|
||||
function URLSearchParams() {
|
||||
this.pairs = [];
|
||||
}
|
||||
|
||||
var prototype = URLSearchParams.prototype;
|
||||
|
||||
prototype.append = function append(name, value) {
|
||||
this.pairs.push([name, value]);
|
||||
};
|
||||
|
||||
prototype.toString = function toString() {
|
||||
return this.pairs.map(function each(pair) {
|
||||
return pair[0] + '=' + encode(pair[1]);
|
||||
}, '').join('&');
|
||||
};
|
||||
|
||||
return URLSearchParams;
|
||||
})(URLSearchParams);
|
||||
Reference in New Issue
Block a user