Skip to content

Commit 21d8ec5

Browse files
committed
Merge branch 'main' into avoid-normalization-side-effects
2 parents f31fc5b + e715e00 commit 21d8ec5

File tree

7 files changed

+57
-9
lines changed

7 files changed

+57
-9
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# 1.1.24 - 31 Oct 2024
2+
Security:
3+
- [#891](https://github.com/elysiajs/elysia/pull/891) Upgrade Cookie to 0.7.x to fix CVE-2024-47764
4+
5+
Bug fix:
6+
- [#885](https://github.com/elysiajs/elysia/pull/885) unwrap transform errors
7+
- [#903](https://github.com/elysiajs/elysia/pull/903) typebox object schemas without properties key
8+
19
# 1.1.23 - 22 Oct 2024
210
Bug fix:
311
- Handle object with `.then` even if it's not promise (looking at you, Drizzle)

bun.lockb

24 Bytes
Binary file not shown.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "elysia",
33
"description": "Ergonomic Framework for Human",
4-
"version": "1.1.23",
4+
"version": "1.1.24",
55
"author": {
66
"name": "saltyAom",
77
"url": "https://github.com/SaltyAom",
@@ -104,14 +104,14 @@
104104
},
105105
"dependencies": {
106106
"@sinclair/typebox": "0.32.34",
107-
"cookie": "^0.6.0",
107+
"cookie": "^1.0.1",
108108
"fast-decode-uri-component": "^1.0.1",
109109
"openapi-types": "^12.1.3"
110110
},
111111
"devDependencies": {
112112
"@types/benchmark": "^2.1.5",
113113
"@types/bun": "^1.1.2",
114-
"@types/cookie": "^0.6.0",
114+
"@types/cookie": "^1.0.0",
115115
"@typescript-eslint/eslint-plugin": "^6.17.0",
116116
"@typescript-eslint/parser": "^6.17.0",
117117
"benchmark": "^2.1.4",

src/compose.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export const hasAdditionalProperties = (
7979
const properties = schema.properties as Record<string, TAnySchema>
8080

8181
if ('additionalProperties' in schema) return schema.additionalProperties
82+
if ('patternProperties' in schema) return false
8283

8384
for (const key of Object.keys(properties)) {
8485
const property = properties[key]
@@ -2343,9 +2344,10 @@ export const composeErrorHandler = (
23432344
}
23442345

23452346
fnLiteral += `if(error.constructor.name === "ValidationError" || error.constructor.name === "TransformDecodeError") {
2346-
set.status = error.status ?? 422
2347+
const reportedError = error.error ?? error
2348+
set.status = reportedError.status ?? 422
23472349
return new Response(
2348-
error.message,
2350+
reportedError.message,
23492351
{
23502352
headers: Object.assign(
23512353
{ 'content-type': 'application/json'},

src/dynamic-handle.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { redirect, signCookie, StatusMap } from './utils'
1717
import { parseCookie } from './cookies'
1818

1919
import type { Handler, LifeCycleStore, SchemaValidator } from './types'
20+
import { TransformDecodeError } from '@sinclair/typebox/value'
2021

2122
// JIT Handler
2223
export type DynamicHandler = {
@@ -420,11 +421,13 @@ export const createDynamicHandler =
420421

421422
return (context.response = mapResponse(response, context.set))
422423
} catch (error) {
423-
if ((error as ElysiaErrors).status)
424-
set.status = (error as ElysiaErrors).status
425-
424+
const reportedError = (error instanceof TransformDecodeError && error.error)
425+
? error.error
426+
: error
427+
if ((reportedError as ElysiaErrors).status)
428+
set.status = (reportedError as ElysiaErrors).status
426429
// @ts-expect-error private
427-
return app.handleError(context, error)
430+
return app.handleError(context, reportedError)
428431
} finally {
429432
for (const afterResponse of app.event.afterResponse)
430433
await afterResponse.fn(context as any)

test/core/compose.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { describe, expect, it } from 'bun:test'
2+
import { Type } from '@sinclair/typebox'
3+
import { hasAdditionalProperties } from '../../src/compose'
4+
5+
describe('hasAdditionalProperties', () => {
6+
it('should handle object schemas without properties key', () => {
7+
const schema = Type.Intersect([
8+
Type.Object({ a: Type.String() }),
9+
// Record schemas does not have properties key, instead it has patternProperties
10+
Type.Record(Type.Number(), Type.String())
11+
])
12+
expect(hasAdditionalProperties(schema)).toBe(false)
13+
})
14+
})

test/core/handle-error.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,25 @@ describe('Handle Error', () => {
204204
'APIError'
205205
)
206206
})
207+
208+
it('handle error in Transform', async () => {
209+
const route = new Elysia().get('/', ({query: {aid}}) => aid, {
210+
query: t.Object({
211+
aid: t.Transform(t.String())
212+
.Decode((value) => {
213+
throw new NotFoundError('foo')
214+
})
215+
.Encode((value) => `1`)
216+
})
217+
})
218+
219+
let response = await (new Elysia({ aot: false })).use(route).handle(req('/?aid=a'))
220+
expect(response.status).toEqual(404)
221+
expect(await response.text()).toEqual('foo')
222+
223+
response = await (new Elysia({aot: true})).use(route).handle(req('/?aid=a'))
224+
expect(response.status).toEqual(404)
225+
expect(await response.text()).toEqual('foo')
226+
})
227+
207228
})

0 commit comments

Comments
 (0)