Skip to content

Commit 068783b

Browse files
committed
Use URLSearchParams
1 parent d45d2a0 commit 068783b

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ This driver uses semantic versioning:
2626
Any names used when creating/ensuring indexes or passed to any methods that
2727
expect an `IndexSelector` will automatically be NFC normalized.
2828

29+
- Internal querystring handling logic now uses `URLSearchParams` instead of
30+
node `querystring` module
31+
32+
This change should be backwards compatible but may produce different results
33+
when relying on undefined behavior in custom (e.g. Foxx) routes.
34+
2935
## [8.1.0] - 2022-12-19
3036

3137
### Added

src/lib/querystringify.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
import { ParsedUrlQueryInput, stringify } from "querystring";
2-
3-
// eslint-disable-next-line @typescript-eslint/ban-types
4-
function clean<T extends {}>(obj: T) {
5-
const result = {} as typeof obj;
6-
for (const key of Object.keys(obj)) {
7-
const value = (obj as any)[key];
1+
export function querystringify(obj: Record<string, any>) {
2+
const params = new URLSearchParams();
3+
for (const [key, value] of Object.entries(obj)) {
84
if (value === undefined) continue;
9-
(result as any)[key] = value;
5+
if (!Array.isArray(value)) {
6+
params.append(key, value);
7+
} else {
8+
for (const item of value) {
9+
params.append(key, item);
10+
}
11+
}
1012
}
11-
return result;
12-
}
13-
14-
export function querystringify(obj: ParsedUrlQueryInput) {
15-
return stringify(clean(obj));
13+
return String(params);
1614
}

0 commit comments

Comments
 (0)