Skip to content

Commit 287dd53

Browse files
authored
Merge pull request #963 from macabeus/fix-issue-946
🔧 fix array parser on query string when AOT is off
2 parents 9ab72e8 + f248a36 commit 287dd53

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

src/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export type Context<
107107
{
108108
body: Route['body']
109109
query: undefined extends Route['query']
110-
? Record<string, string | undefined>
110+
? Record<string, string | string[] | undefined>
111111
: Route['query']
112112
params: undefined extends Route['params']
113113
? undefined extends Path

src/dynamic-handle.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ import {
99
} from './error'
1010

1111
import type { Context } from './context'
12-
import { type error } from './error'
1312

14-
import { parseQuery, parseQueryFromURL } from './fast-querystring'
13+
import { parseQuery } from './fast-querystring'
1514

1615
import { redirect, signCookie, StatusMap } from './utils'
1716
import { parseCookie } from './cookies'
@@ -177,7 +176,7 @@ export const createDynamicHandler =
177176
context.body = body
178177
context.params = handler?.params || undefined
179178
context.query =
180-
qi === -1 ? {} : parseQueryFromURL(url.substring(qi + 1))
179+
qi === -1 ? {} : parseQuery(url.substring(qi + 1))
181180

182181
context.headers = {}
183182
for (const [key, value] of request.headers.entries())

test/core/dynamic.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,14 @@ describe('Dynamic Mode', () => {
144144
})
145145

146146
it('validate', async () => {
147-
const app = new Elysia({
148-
// aot: false
149-
}).post('/', ({ query: { id } }) => id.toString(), {
147+
const app = new Elysia({ aot: false }).post('/', ({ query: { id, arr } }) => `${id} - ${arr}`, {
150148
body: t.Object({
151149
username: t.String(),
152150
password: t.String()
153151
}),
154152
query: t.Object({
155-
id: t.String()
153+
id: t.String(),
154+
arr: t.Array(t.String()),
156155
}),
157156
response: {
158157
200: t.String()
@@ -161,13 +160,14 @@ describe('Dynamic Mode', () => {
161160

162161
const res = await app
163162
.handle(
164-
post('/?id=me', {
163+
post('/?id=me&arr=v1&arr=v2', {
165164
username: 'username',
166165
password: 'password'
167166
})
168167
)
169168
.then((x) => x.text())
170-
expect(res).toBe('me')
169+
170+
expect(res).toBe('me - v1,v2')
171171
})
172172

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

0 commit comments

Comments
 (0)