Thanks to visit codestin.com
Credit goes to github.com

Skip to content

net/ghttp: The new version of nested field parsing is invalid #3789

@shuqingzai

Description

@shuqingzai

Go version

go version go1.21.13 darwin/amd64

GoFrame version

2.7.3

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

2.7.2 以下代码运行正常,但是 2.7.3 解析请求参数错误

config.yaml

server:
  address:     ":8199"
  openapiPath: "/api.json"
  swaggerPath: "/swagger"

main.go

package main

import (
	"context"

	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
)

type ItemInput struct {
	ItemFirst
}

type ItemSecondThird struct {
	// SecondID ...
	SecondID uint64 `json:"secondId,string" dc:"SecondID" v:"required"`
	// ThirdID ...
	ThirdID uint64 `json:"thirdId,string" dc:"ThirdID" v:"required"`
}

type ItemFirst struct {
	// ID ID
	ID uint64 `json:"id,string" dc:"ID"`

	ItemSecondThird
}

type HelloReq struct {
	g.Meta `path:"/hello" method:"GET"`

	ItemInput
}
type HelloRes struct {
	ItemInput
}

type Hello struct{}

func (Hello) Say(ctx context.Context, req *HelloReq) (res *HelloRes, err error) {
	g.Log().Debugf(ctx, `receive say: %+v`, req)
	res = &HelloRes{
		ItemInput: req.ItemInput,
	}
	return
}

func main() {
	s := g.Server()
	s.Use(ghttp.MiddlewareHandlerResponse)
	s.Group("/", func(group *ghttp.RouterGroup) {
		group.Bind(
			new(Hello),
		)
	})
	s.Run()
}

What did you see happen?

分别使用不同版本启动服务,得到不同的响应结果

使用请求

curl -X GET 'http://127.0.0.1:8199/hello?id=&secondId=157889372459384832&thirdId=157889372459384833' \
-H 'Host: 127.0.0.1:8199'
  1. 2.7.2

正确解析请求参数 secondId

{"code":0,"message":"","data":{"id":"0","secondId":"157889372459384832","thirdId":"157889372459384833"}}
  1. 2.7.3

没有正确解析请求参数 secondId ,甚至说试多几次,有时候 thirdId 的值会被赋值到 secondId ,值被缓存??

{"code":0,"message":"","data":{"id":"0","secondId":"0","thirdId":"157889372459384833"}}

What did you expect to see?

参数被正确解析

Metadata

Metadata

Assignees

Labels

bugIt is confirmed a bug, but don't worry, we'll handle it.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions