normalize formdata with get instead of getAll

This commit is contained in:
saltyaom
2026-06-17 05:25:14 +07:00
parent 56310be961
commit 8358ff9efb
4 changed files with 29 additions and 9 deletions
+4
View File
@@ -1,3 +1,7 @@
# 1.4.29 - 17 Jun 2026
Bug fix:
- normalize a `multipart/form-data` with `.get` instead of `.getAll` for faster performance
# 1.4.28 - 17 Mar 2025
Feature:
- [#1803](https://github.com/elysiajs/elysia/pull/1803) stream response with pull based backpressure
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "elysia",
"description": "Ergonomic Framework for Human",
"version": "1.4.28",
"version": "1.4.29",
"author": {
"name": "saltyAom",
"url": "https://github.com/SaltyAom",
+3 -2
View File
@@ -58,9 +58,10 @@ export const WebStandardAdapter: ElysiaAdapter = {
`const m=k.match(/^(.+)\\[(\\d+)\\]$/);` +
`return m?{name:m[1],index:parseInt(m[2],10)}:null` +
`}\n` +
`for(const key of form.keys()){` +
`const grouped=new Map()\n` +
`form.forEach((v,k)=>{const l=grouped.get(k);if(l)l.push(v);else grouped.set(k,[v])})\n` +
`for(const [key,value] of grouped){` +
`if(c.body[key])continue\n` +
`const value=form.getAll(key)\n` +
`let finalValue\n` +
`if(value.length===1){\n` +
`const sv=value[0]\n` +
+21 -6
View File
@@ -287,10 +287,15 @@ export const createDynamicHandler = (app: AnyElysia) => {
body = {}
const form = await request.formData()
for (const key of form.keys()) {
const grouped = new Map<string, any[]>()
form.forEach((v, k) => {
const list = grouped.get(k)
if (list) list.push(v)
else grouped.set(k, [v])
})
for (const [key, value] of grouped) {
if (body[key]) continue
const value = form.getAll(key)
const finalValue = normalizeFormValue(value)
if (key.includes('.') || key.includes('['))
@@ -347,10 +352,15 @@ export const createDynamicHandler = (app: AnyElysia) => {
body = {}
const form = await request.formData()
for (const key of form.keys()) {
const grouped = new Map<string, any[]>()
form.forEach((v, k) => {
const list = grouped.get(k)
if (list) list.push(v)
else grouped.set(k, [v])
})
for (const [key, value] of grouped) {
if (body[key]) continue
const value = form.getAll(key)
const finalValue = normalizeFormValue(value)
if (key.includes('.') || key.includes('['))
@@ -417,10 +427,15 @@ export const createDynamicHandler = (app: AnyElysia) => {
body = {}
const form = await request.formData()
for (const key of form.keys()) {
const grouped = new Map<string, any[]>()
form.forEach((v, k) => {
const list = grouped.get(k)
if (list) list.push(v)
else grouped.set(k, [v])
})
for (const [key, value] of grouped) {
if (body[key]) continue
const value = form.getAll(key)
const finalValue = normalizeFormValue(value)
if (key.includes('.') || key.includes('['))