Skip to content

Commit 9d9eaed

Browse files
authored
fix: Skips other params after an object param (#24)
* test: Empty object serialization Add test cases for serializeUrlSearchParams function. * Update serialization test to include 'q' parameter * Fix indentation in serialization test * fix: Skips other params after an object param
1 parent 9569791 commit 9d9eaed

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/lib/serialize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const nestedUpdateUrlSearchParams = (
3333
const currentPath = [...path, key]
3434
if (isPlainObject(value)) {
3535
nestedUpdateUrlSearchParams(searchParams, value, currentPath)
36-
return
36+
continue
3737
}
3838

3939
const name = currentPath.join('.')

test/serialization.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,30 @@ test('serializes plain objects', (t) => {
108108
}),
109109
'bar.baz=1&bar.baz=a&foo=1',
110110
)
111+
112+
t.is(
113+
serializeUrlSearchParams({
114+
foo: {},
115+
bar: 2,
116+
}),
117+
'bar=2',
118+
)
119+
120+
t.is(
121+
serializeUrlSearchParams({
122+
foo: { x: {} },
123+
bar: 2,
124+
}),
125+
'bar=2',
126+
)
127+
128+
t.is(
129+
serializeUrlSearchParams({
130+
foo: {},
131+
bar: { baz: { x: { z: null, t: {} }, q: {} } },
132+
}),
133+
'bar.baz.x.z=',
134+
)
111135
})
112136

113137
test('cannot serialize keys containing a .', (t) => {

0 commit comments

Comments
 (0)