Skip to content
Myr

fix(validator): don't return a FormData if formData is cached (#3067)

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

* fix(validator): don't return a FormData if formData is cached * fixed typo * test the value

authored by Yusuke Wada · committed by GitHub · parent 94f47ec · Browse files · 2 files+55 added−23 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+55 added−23 removed

  • tests:+30 added−0 removed
  • other:+25 added−23 removed

2 files+55 added−23 removed

modified:src/validator/validator.test.ts+30 added
908 unmodified lines
909 return c.text('foo')910 }911 )912913 app.post(914 '/cached',915 async (c, next) => {916 await c.req.parseBody()917 await next()918 },919 validator('form', (value) => {920 if (value instanceof FormData) {921 throw new Error('The value should not be a FormData')922 }923 return value924 }),925 (c) => {926 const v = c.req.valid('form')927 return c.json(v)928 }929 )930931 it('Should not throw the error with c.req.parseBody()', async () => {932 const body = new FormData()933 body.append('foo', 'bar')934 const req = new Request('http://localhost', {
2 unmodified lines
937 })938 const res = await app.request(req)939 expect(res.status).toBe(200)940 })941942 it('Should not be an instance of FormData if the formData is cached', async () => {943 const body = new FormData()944 body.append('foo', 'bar')945 const req = new Request('http://localhost/cached', {946 method: 'POST',947 body: body,948 })949 const res = await app.request(req)950 expect(res.status).toBe(200)951 expect(await res.json()).toEqual({ foo: 'bar' })952 })953 })954})955956describe('Async validator function', () => {
112 unmodified lines
modified:src/validator/validator.ts+25 added-23 removed