elysiajs / elysia

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

Query params following an array query are parsed as array items #749

Closed aooen closed 1 month ago

aooen commented 1 month ago

What version of Elysia.JS is running?

1.1.3

What platform is your computer?

Microsoft Windows NT 10.0.22000.0 x64

What steps can reproduce the bug?

import Elysia, { t } from 'elysia'

const app = new Elysia().get('/', ({ query }) => query, {
  query: t.Object({
    leading: t.String(),
    arr: t.Array(t.String()),
    trailing: t.String(),
  }),
})

const res = await app.fetch(new Request('http://localhost/?leading=foo&arr=bar&arr=baz&trailing=qux'))
console.log(await res.json())

What is the expected behavior?

{
    "leading": "foo",
    "arr": ["bar", "baz"],
    "trailing": "qux",
}

What do you see instead?

{
    "leading": "foo",
    "arr": ["bar", "baz", "ling=qux"],
    "trailing": "qux",
}

Additional information

"ling=qux" appears to be 'trailing=qux'.slice('arr='.length). There's no validation of param key. This seems to be happening since version 1.1.0.

SaltyAom commented 1 month ago

Should have been fixed on e946da4, published under 1.1.4