Skip to content

Commit 6c63dc0

Browse files
committed
🔧 fix: safely unwrap t.Record
1 parent dafd31b commit 6c63dc0

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.3.22 - 6 Sep 2025
2+
Bug fix:
3+
- safely unwrap t.Record
4+
15
# 1.3.21 - 31 Aug 2025
26
Bug fix:
37
- [#1356](https://github.com/elysiajs/elysia/pull/1356) webSocket validation error handling in BunAdapter

example/a.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
import { Elysia } from '../src'
1+
import { Elysia, t } from '../src'
2+
import { req } from '../test/utils'
23

3-
const plugin1 = new Elysia().derive({ as: 'scoped' }, () => ({
4-
hello: 'world'
5-
}))
4+
const app = new Elysia()
5+
.get('/', () => 'SAFE', {
6+
query: t.Record(t.String(), t.String())
7+
})
68

7-
const plugin2 = new Elysia()
8-
.use(plugin1)
9-
.derive({ as: 'scoped' }, ({ hello }) => ({ hello }))
9+
const response = await app.handle(req('/?x=1'))
1010

11-
const app = new Elysia()
12-
.use(plugin2)
13-
// This is undefined
14-
.get('/', ({ hello }) => typeof hello)
15-
.listen(3000)
11+
console.log(response.status)

src/compose.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -651,12 +651,12 @@ export const composeHandler = ({
651651
if (
652652
schema &&
653653
(schema.type === 'object' ||
654-
(schema[Kind] === 'Import' && schema.$defs[schema.$ref]))
654+
(schema[Kind] === 'Import' && schema.$defs?.[schema.$ref]))
655655
) {
656656
const properties =
657-
schema.properties ?? schema.$defs[schema.$ref].properties
657+
schema.properties ?? schema.$defs?.[schema.$ref]?.properties
658658

659-
if (!validator.query!.hasAdditionalProperties)
659+
if (properties && !validator.query!.hasAdditionalProperties)
660660
for (const [key, _value] of Object.entries(properties)) {
661661
let value = _value as TAnySchema
662662

test/validator/validator.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,14 @@ describe('Validator Additional Case', () => {
160160
expect(res[0].status).toBe(422)
161161
expect(res[1].status).toBe(200)
162162
})
163+
164+
it('handle record', async () => {
165+
const app = new Elysia().get('/', () => 'SAFE', {
166+
query: t.Record(t.String(), t.String())
167+
})
168+
169+
const response = await app.handle(req('/?x=1'))
170+
171+
expect(response.status).toBe(200)
172+
})
163173
})

0 commit comments

Comments
 (0)