Skip to content

Commit

Permalink
🔧 fix array parser on query string when AOT is off
Browse files Browse the repository at this point in the history
  • Loading branch information
macabeus committed Dec 22, 2024
1 parent 9ab72e8 commit f248a36
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export type Context<
{
body: Route['body']
query: undefined extends Route['query']
? Record<string, string | undefined>
? Record<string, string | string[] | undefined>
: Route['query']
params: undefined extends Route['params']
? undefined extends Path
Expand Down
5 changes: 2 additions & 3 deletions src/dynamic-handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import {
} from './error'

import type { Context } from './context'
import { type error } from './error'

import { parseQuery, parseQueryFromURL } from './fast-querystring'
import { parseQuery } from './fast-querystring'

import { redirect, signCookie, StatusMap } from './utils'
import { parseCookie } from './cookies'
Expand Down Expand Up @@ -177,7 +176,7 @@ export const createDynamicHandler =
context.body = body
context.params = handler?.params || undefined
context.query =
qi === -1 ? {} : parseQueryFromURL(url.substring(qi + 1))
qi === -1 ? {} : parseQuery(url.substring(qi + 1))

context.headers = {}
for (const [key, value] of request.headers.entries())
Expand Down
12 changes: 6 additions & 6 deletions test/core/dynamic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,14 @@ describe('Dynamic Mode', () => {
})

it('validate', async () => {
const app = new Elysia({
// aot: false
}).post('/', ({ query: { id } }) => id.toString(), {
const app = new Elysia({ aot: false }).post('/', ({ query: { id, arr } }) => `${id} - ${arr}`, {
body: t.Object({
username: t.String(),
password: t.String()
}),
query: t.Object({
id: t.String()
id: t.String(),
arr: t.Array(t.String()),
}),
response: {
200: t.String()
Expand All @@ -161,13 +160,14 @@ describe('Dynamic Mode', () => {

const res = await app
.handle(
post('/?id=me', {
post('/?id=me&arr=v1&arr=v2', {
username: 'username',
password: 'password'
})
)
.then((x) => x.text())
expect(res).toBe('me')

expect(res).toBe('me - v1,v2')
})

it('handle non query fallback', async () => {
Expand Down

0 comments on commit f248a36

Please sign in to comment.