Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validator: FormData validation fails when content-type header does not have a space #3285

Closed
Ernxst opened this issue Aug 17, 2024 · 0 comments · Fixed by #3286
Closed

Validator: FormData validation fails when content-type header does not have a space #3285

Ernxst opened this issue Aug 17, 2024 · 0 comments · Fixed by #3286
Labels

Comments

@Ernxst
Copy link
Contributor

Ernxst commented Aug 17, 2024

What version of Hono are you using?

4.5.5

What runtime/platform is your app running on?

Cloudflare Workers

What steps can reproduce the bug?

  1. Define a route with a validator schema (I'm using the example in the docs)
const route = app.post(
  '/posts',
  zValidator(
    'form',
    z.object({
      body: z.string(),
    })
  ),
  (c) => {
    const validated = c.req.valid('form')
    // ... use your validated data
  }
)
  1. Call endpoint with form data matching expecting shape.

What is the expected behavior?

c.req.valid('form') to parse the form data.

What do you see instead?

A validation error is thrown. Adding logs inside validator.js (in my node_modules) shows that the validator function is receiving an empty object. It seems that the multipart regex test fails so an empty object is returned. In my case, it fails because the Content-Type header does not have a space after the semi-colon (multipart/form-data;boundary=2b6246d41cda0544685d0b416bddc327) like the regex is expecting.

Additional information

This used to work fine, not clue what it is in my stack that has removed the space in the Content-Type header.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant