Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add allowFieldsDuplication options #3971

Merged
merged 1 commit into from
Jul 26, 2024
Merged

Conversation

czy88840616
Copy link
Member

@czy88840616 czy88840616 commented Jul 25, 2024

Checklist
  • npm test passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)
Description of change

fix: #3970

@czy88840616 czy88840616 added the pr: polish This PR adds a very minor behavior improvement that users will enjoy. label Jul 25, 2024
@czy88840616 czy88840616 merged commit 227a1e5 into main Jul 26, 2024
7 checks passed
@czy88840616 czy88840616 deleted the support_duplicate_fileds branch July 26, 2024 01:49
@kaesi0
Copy link

kaesi0 commented Jul 26, 2024

我是升级upload组件,开启allowFieldsDuplication配置就行了么?现在版本是3.16.5

@czy88840616
Copy link
Member Author

已发布3.16.6

@kaesi0
Copy link

kaesi0 commented Jul 26, 2024

当uplaod组件配置对象中allowFieldsDuplication参数设置为true时,在post请求中,原来参数校验正常的DTO会开始报错,表现为从DTO的第一个字段开始,即便请求字段类型是正确的,但是校验也不会通过。

示例:
在路由/addTag中通过AddTagDTO来校验请求参数

 @Post('/addTag')
  async addTag(@Files() files, @Fields() fields: AddTagDTO) {
    return await this.tagService.addTag(fields, files);
  }

当DTO是:
image
实际请求为:
image
返回参数验证错误:

"level" must be a number"

当DTO更改为:
image
实际请求为:
image
返回参数验证错误:

"name" must be a string"

以上问题在allowFieldsDuplication参数设置为false或不设置allowFieldsDuplication参数时,参数校验正常,能得到校验完成后的fields对象,但请求中数组类参数被覆盖的问题仍然存在。

@kaesi0
Copy link

kaesi0 commented Jul 26, 2024

post请求的类型还是form-data

@czy88840616
Copy link
Member Author

你是要单个的时候非数组,多个才变数组?

@kaesi0
Copy link

kaesi0 commented Jul 26, 2024

其实只要能正确收到数组参数。在form-data请求,数组类型的参数是通过多个同名参数不同赋值来传递的,问题在于现在收到的参数就被覆盖掉了,只会有1个,其实只要不被覆盖,像在query参数中querystring 能正确解析出数组参数,无论是1个参数,还是多个同名但不同值的参数,Validate组件是能解析成数组参数的,这个不影响,问题的关键在于form-data请求中,多个同名但不同值的参数前面的会被覆盖,收到就只有1个了,所以Validate校验过后也只有1个

@czy88840616
Copy link
Member Author

czy88840616 commented Jul 26, 2024

\3.6.16现在就已经支持数组了,只是你开启了配置,单个的值也变成了数组。#3981 现在会在单个 field 的时候调整回去。

@czy88840616
Copy link
Member Author

czy88840616 commented Jul 26, 2024

3.6.17 处理成同名 field 多余 1 个才变成数组。

czy88840616 added a commit that referenced this pull request Sep 29, 2024
@7kyun
Copy link

7kyun commented Oct 30, 2024

busboy 不支持吗

@czy88840616
Copy link
Member Author

busboy 拿到的 fields 是数组(好像文档没改),没有这个覆盖的问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: polish This PR adds a very minor behavior improvement that users will enjoy.
Development

Successfully merging this pull request may close these issues.

form-data请求中同名array类型参数会被覆盖,只能收到最后一个参数
3 participants