elysiajs / elysia

Ergonomic Framework for Humans
https://elysiajs.com
MIT License
10.63k stars 226 forks source link

Parsing of route with multiple optional params fails, when params are separated by characters other than `/` #881

Open bertspaan opened 1 month ago

bertspaan commented 1 month ago

What version of Elysia is running?

1.1.19

What platform is your computer?

Darwin 23.5.0 arm64 arm

What steps can reproduce the bug?

Create an Elysia instance with a route that contains multiple optional params (separated by a @ and . character, not by a /), validation of params fails:

import { Elysia, t } from 'elysia'

new Elysia()
  .get(
    '/images/:imageId@:version?.:ext?',
    ({ params }) => {
      return { params }
    },
    {
      params: t.Object({
        imageId: t.String(),
        version: t.Optional(t.String()),
        ext: t.Optional(t.String())
      })
    }
  )
  .listen(3000)

What is the expected behavior?

A params object of the following form:

t.Object({
  imageId: t.String(),
  version: t.Optional(t.String()),
  ext: t.Optional(t.String())
})

What do you see instead?

A TypeBox error:

{
  "type": "validation",
  "on": "params",
  "summary": "Property 'imageId' is missing",
  ...
}

Additional information

No response

Have you try removing the node_modules and bun.lockb and try again yet?

Yes!