Skip to content

Commit 505e8a6

Browse files
authored
Update fetch.js
The implementation of encodeQueryData method changes to support encoding of nested objects.
1 parent 385b38f commit 505e8a6

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/utils/fetch.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,16 @@
3131
/*
3232
* Creates URL request path
3333
*/
34-
const encodeQueryData = data => Object.keys(data)
35-
.filter(k => typeof data[k] !== 'object')
36-
.map(k => encodeURIComponent(k) + '=' + encodeURIComponent(data[k]))
37-
.join('&');
34+
const encodeQueryData = (data, nesting = '') => {
35+
const pairs = Object.entries(data).map(([key, val]) => {
36+
if (typeof val === 'object') {
37+
return encodeQueryData(val, nesting + `${key}.`);
38+
} else {
39+
return encodeURIComponent(nesting + key) + '=' + encodeURIComponent(val);
40+
}
41+
});
42+
return pairs.join('&');
43+
};
3844

3945
const bodyTypes = [
4046
window.ArrayBuffer,

0 commit comments

Comments
 (0)