Skip to content

Commit

Permalink
Merge pull request #209 from contentstack/fix/DX-933_new
Browse files Browse the repository at this point in the history
fix: replaced encodeUriComponent with urlsearchparams
  • Loading branch information
netrajpatel authored Sep 2, 2024
2 parents 5b1133f + 5d0b0b9 commit 6a11a21
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "contentstack",
"version": "3.20.4",
"version": "3.20.5",
"description": "Contentstack Javascript SDK",
"homepage": "https://www.contentstack.com/",
"author": {
Expand Down
35 changes: 16 additions & 19 deletions src/core/lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,25 @@ export default function Request(stack, fetchOptions) {
let requestParams = stack.requestParams;
return new Promise(function(resolve, reject) {
let queryParams;
let serialize = function(obj, prefix) {

let str = [],
p;
if (typeof obj === "object" && obj.length !== undefined) {
for (var i = 0, _i = obj.length; i < _i; i++) {
str.push(prefix + '[]=' + obj[i]);
}
} else {
for (const p in obj) {
let k = prefix ? prefix + "[" + p + "]" : p,
v = obj[p];
str.push((v !== null && typeof v === "object" && p !== 'query') ?
serialize(v, k) :
k + "=" + encodeURIComponent(p !== 'query' ? v : JSON.stringify(v)));
}

const params = new URLSearchParams();
let serialize = function (obj, prefix) {
if (typeof obj === 'object' && obj.length !== undefined) {
for (let i = 0, _i = obj.length; i < _i; i++) {
params.append(prefix + '[]', obj[i]);
}
} else {
for (const p in obj) {
let k = prefix ? prefix + '[' + p + ']' : p,
v = obj[p];
v !== null && typeof v === 'object' && p !== 'query'
? serialize(v, k)
: params.append(k, p !== 'query' ? v : JSON.stringify(v));
}
return str.join("&");
}
return params.toString();
};



// setting headers
requestParams.headers['Content-Type'] = 'application/json; charset=UTF-8';
requestParams.headers['X-User-Agent'] = 'contentstack-delivery-javascript-{{PLATFORM}}/' + version;
Expand Down

0 comments on commit 6a11a21

Please sign in to comment.