Skip to content

Commit 12a3178

Browse files
mahsashadimahsa shadi
authored and
mahsa shadi
committed
Improve serialization of VFS URL query parameters
1 parent 385b38f commit 12a3178

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/utils/fetch.js

+10-4
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)