-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Validator: FormData validation fails when content-type header does not have a space #3285
Copy link
Copy link
Closed
Labels
Description
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?
- 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
}
)- 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.
Reactions are currently unavailable