-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed
toFormData
regression bug (unreleased) with Array-like object…
…s 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>
- Loading branch information
1 parent
e762cf7
commit c05ad48
Showing
13 changed files
with
245 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
|
||
var utils = require('../utils'); | ||
var toFormData = require('./toFormData'); | ||
var platform = require('../platform/'); | ||
|
||
module.exports = function toURLEncodedForm(data) { | ||
return toFormData(data, new platform.classes.URLSearchParams(), { | ||
visitor: function(value, key, path, helpers) { | ||
if (platform.isNode && utils.isBuffer(value)) { | ||
this.append(key, value.toString('base64')); | ||
return false; | ||
} | ||
|
||
return helpers.defaultVisitor.apply(this, arguments); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
isBrowser: true, | ||
classes: { | ||
URLSearchParams: require('./classes/URLSearchParams') | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
module.exports = require('./node/'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
var url = require('url'); | ||
|
||
module.exports = url.URLSearchParams; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
isNode: true, | ||
classes: { | ||
URLSearchParams: require('./classes/URLSearchParams') | ||
} | ||
}; |
Oops, something went wrong.