Skip to content

Commit d694734

Browse files
authored
Append suffix to param key to uniquify duplicate param keys (#232)
1 parent 8f5f8f2 commit d694734

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/api.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ export default class Api {
2626
body?: string
2727
) {
2828
const paramsData: Record<string, string> = {};
29-
29+
// In order to allow for duplicate URL params add a suffix to it to
30+
// uniquify the key. We strip this suffix off as part of
31+
// constructing the final URL in _request()
32+
let i = 0;
3033
(params ?? []).forEach(([key, value]) => {
3134
if (key) {
32-
paramsData[key] = value;
35+
paramsData[key + '__' + i] = value;
36+
i++;
3337
}
3438
});
3539

@@ -140,7 +144,7 @@ export default class Api {
140144
req.url +
141145
(req.url.search(/\?/) >= 0 ? '&' : '?') +
142146
Object.entries(params)
143-
.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
147+
.map(([k, v]) => `${encodeURIComponent(k.replace(/__\d+$/, ''))}=${encodeURIComponent(v)}`)
144148
.join('&');
145149
}
146150

0 commit comments

Comments
 (0)