From 5099a50252efcbf5c0e43181e8efe9b2da8601ec Mon Sep 17 00:00:00 2001 From: leonardoyhl <34596552+leonardoyhl@users.noreply.github.com> Date: Wed, 22 May 2024 21:32:07 +0800 Subject: [PATCH] fix: new-request error when create request from cURL if some parameter(s) in form-urlencoded type data missing '=' (#2290) --- packages/bruno-app/src/utils/curl/curl-to-json.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/bruno-app/src/utils/curl/curl-to-json.js b/packages/bruno-app/src/utils/curl/curl-to-json.js index 8313e0a79..82eb0be95 100644 --- a/packages/bruno-app/src/utils/curl/curl-to-json.js +++ b/packages/bruno-app/src/utils/curl/curl-to-json.js @@ -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;