dubbo icon indicating copy to clipboard operation
dubbo copied to clipboard

[Bug] application/x-www-form-urlencoded There is a problem with parameter parsing

Open funky-eyes opened this issue 1 year ago • 0 comments

Pre-check

  • [X] I am sure that all the content I provide is in English.

Search before asking

  • [X] I had searched in the issues and found no similar issues.

Apache Dubbo Component

Java SDK (apache/dubbo)

Dubbo Version

dubbo 3.2.16

Steps to reproduce this issue

    @POST
    @Path("/test")
    public ResponseVO test(
        @FormParam("path") @QueryParam("path")  String path,@FormParam("body") @QueryParam("body")  String body) {
......
}
POST http://localhost:8087/test
Content-Type: application/x-www-form-urlencoded

body=a&
path=a

After the request, both path and body are null, because the following arraylist always reads only the 0th argument.

    public Object decode(byte[] body, Class<?> targetType, Type type) throws Exception {
        Object map = DataParseUtils.multipartFormConvert(body, targetType);
        Map valuesMap = (Map) map;
        if (Map.class.isAssignableFrom(targetType)) {
            return map;
        } else if (DataParseUtils.isTextType(targetType)) {

            // only fetch  first
            Set set = valuesMap.keySet();
            ArrayList arrayList = new ArrayList<>(set);
            Object key = arrayList.get(0);
            Object value = valuesMap.get(key);
            if (value == null) {
                return null;
            }
            return DataParseUtils.stringTypeConvert(targetType, String.valueOf(((List) value).get(0)));

        }
....
}

然后ParamProviderParamParser在解析为null时,会set下标为null,而在它之前的BodyProviderParamParser已经将值解析后进行set,却被前者给覆盖为null Then, when ParamProviderParamParser parses to null, it sets the index to null, while the previous BodyProviderParamParser has already parsed and set the value, which gets overridden to null by the former

What you expected to happen

如果其中一个parser解析出null值,不应该进行set,然后应该将ArgInfo向下传入,而不是传入type,type中没有paramName,所以在BodyProviderParamParser中无法找到对应的Param If one of the parsers parses a null value, it should not perform the set action, and the ArgInfo should be passed into the parser instead of just the type. The type does not contain the paramName, so the corresponding parameter cannot be found in BodyProviderParamParser

Anything else

No response

Are you willing to submit a pull request to fix on your own?

  • [X] Yes I am willing to submit a pull request on my own!

Code of Conduct

funky-eyes avatar Sep 19 '24 06:09 funky-eyes