Skip to content
Myr

fix(client): skip an undefined entry inside a form array (#5280)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Yusuke Wada · committed by GitHub · parent 2059584 · Browse files · 2 files+35 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+35 added−0 removed

  • tests:+32 added−0 removed
  • other:+3 added−0 removed

2 files+35 added−0 removed

modified:src/client/client.test.ts+32 added
519 unmodified lines
520 })521 })522})523524describe('Form arrays containing undefined', () => {525 const app = new Hono().post(526 '/',527 validator('form', () => ({}) as { tag: (string | undefined)[] | undefined }),528 async (c) => {529 const body = await c.req.parseBody({ all: true })530 return c.json({ tag: body['tag'] })531 }532 )533 const client = hc<typeof app>('', { fetch: app.request })534535 it('Should not send the literal string "undefined" for an absent entry', async () => {536 const res = await client.index.$post({537 form: {538 tag: ['a', undefined, 'b'],539 },540 })541 expect(res.status).toBe(200)542 expect(await res.json()).toEqual({ tag: ['a', 'b'] })543 })544545 it('Should keep an empty string in an array', async () => {546 const res = await client.index.$post({547 form: {548 tag: ['a', '', 'b'],549 },550 })551 expect(res.status).toBe(200)552 expect(await res.json()).toEqual({ tag: ['a', '', 'b'] })553 })554})555556describe('Optional header and cookie values', () => {557 const app = new Hono().get(558 '/',559 validator('header', () => {
1585 unmodified lines
modified:src/client/client.ts+3 added
67 unmodified lines
68 continue69 }70 if (Array.isArray(v)) {71 for (const v2 of v) {72 if (v2 === undefined) {73 continue74 }75 form.append(k, v2)76 }77 } else {78 form.append(k, v)
167 unmodified lines