fix: new-request error when create request from cURL if some parameter(s) in form-urlencoded type data missing '=' (#2290)

This commit is contained in:
leonardoyhl 2024-05-22 21:32:07 +08:00 committed by GitHub
parent 91b5d0123e
commit 5099a50252
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -48,6 +48,13 @@ function getDataString(request) {
}
const parsedQueryString = querystring.parse(request.data, { sort: false });
// if missing `=`, `query-string` will set value as `null`. Reset value as empty string ('') here.
// https://github.com/sindresorhus/query-string/blob/3d8fbf2328220c06e45f166cdf58e70617c7ee68/base.js#L364-L366
Object.keys(parsedQueryString).forEach((key) => {
if (parsedQueryString[key] === null) {
parsedQueryString[key] = '';
}
});
const keyCount = Object.keys(parsedQueryString).length;
const singleKeyOnly = keyCount === 1 && !parsedQueryString[Object.keys(parsedQueryString)[0]];
const singularData = request.isDataBinary || singleKeyOnly;