Skip to content

Commit 6e2ea51

Browse files
committed
🎉 release: 1.2.23
1 parent 4362a2d commit 6e2ea51

File tree

5 files changed

+27
-37
lines changed

5 files changed

+27
-37
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 1.2.23 - 25 Feb 2025
22
Bug fix:
33
- [#1087](https://github.com/elysiajs/elysia/pull/1087) websocket to parse string array
4+
- [#1088](https://github.com/elysiajs/elysia/pull/1088) infinite loop when inference body is empty
45

56
# 1.2.22 - 24 Feb 2025
67
Bug fix:

example/a.ts

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,5 @@
11
import { Elysia, t } from '../src'
22
import { hasTransform } from '../src/compose'
3-
import { post } from '../test/utils'
3+
import { post, req } from '../test/utils'
44

5-
console.log(
6-
hasTransform(
7-
t
8-
.Transform(
9-
t.Object({
10-
name: t.String()
11-
})
12-
)
13-
.Decode((x) => x.name)
14-
.Encode((x) => ({ name: x }))
15-
)
16-
)
17-
18-
const app = new Elysia().post('/', ({ body }) => body, {
19-
body: t
20-
.Transform(
21-
t.Object({
22-
name: t.String()
23-
})
24-
)
25-
.Decode((x) => x.name)
26-
.Encode((x) => ({ name: x })),
27-
response: t.String()
28-
})
29-
30-
const res = await app.handle(post('/', { name: 'difhel' }))
31-
32-
console.log(await res.text()) //.toBe('difhel')
33-
console.log(res.status) //.toBe(200)
5+
import { treaty } from '../../eden'

package.json

Lines changed: 1 addition & 1 deletion
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.2.22",
4+
"version": "1.2.23",
55
"author": {
66
"name": "saltyAom",
77
"url": "https://github.com/SaltyAom",

src/sucrose.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ export const sucrose = (
641641
const event = 'fn' in e ? e.fn : e
642642

643643
// parse can be either a function or string
644-
if(typeof event !== "function") continue
644+
if (typeof event !== 'function') continue
645645

646646
const [parameter, body, { isArrowReturn }] = separateFunction(
647647
event.toString()
@@ -651,15 +651,23 @@ export const sucrose = (
651651
const mainParameter = extractMainParameter(rootParameters)
652652

653653
if (mainParameter) {
654-
const aliases = findAlias(mainParameter, body)
654+
const aliases = findAlias(mainParameter, body.slice(1, -1))
655655
aliases.splice(0, -1, mainParameter)
656656

657-
if (!isContextPassToFunction(mainParameter, body, inference))
658-
inferBodyReference(body, aliases, inference)
657+
let code = body
658+
659+
if (
660+
code.charCodeAt(0) === 123 &&
661+
code.charCodeAt(body.length - 1) === 125
662+
)
663+
code = code.slice(1, -1)
664+
665+
if (!isContextPassToFunction(mainParameter, code, inference))
666+
inferBodyReference(code, aliases, inference)
659667

660668
if (
661669
!inference.query &&
662-
body.includes('return ' + mainParameter + '.query')
670+
code.includes('return ' + mainParameter + '.query')
663671
)
664672
inference.query = true
665673
}
@@ -676,6 +684,5 @@ export const sucrose = (
676684
)
677685
break
678686
}
679-
680687
return inference
681688
}

test/sucrose/sucrose.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,14 @@ describe('sucrose', () => {
279279

280280
expect(response.status).toBe(200)
281281
})
282+
283+
it('not death lock on empty', async () => {
284+
const app = new Elysia({ precompile: true })
285+
.onRequest((c) => {})
286+
.get('/', () => 'Hello, World!')
287+
288+
const response = await app.handle(new Request('http://localhost:3000'))
289+
290+
expect(response.status).toBe(200)
291+
})
282292
})

0 commit comments

Comments
 (0)