iris icon indicating copy to clipboard operation
iris copied to clipboard

[Feature Request] ctx.ReadForm fires error if there is no csrf value in struct

Open mostafa-binesh opened this issue 3 years ago • 0 comments

Hey. I realized something today. Consider this example: I put {{ .csrfField }} in the template and CSRF middleware verifies it Processing the request: type LoginUser struct { Username string json:"username" form:"username" validate:"required,min=3" Password string json:"password" form:"password" validate:"required,min=4" } ...

func Proccesing(ctx iris.Context) { user := LoginUser{} err := ctx.ReadForm(&user) if err != nil { ctx.Writef("Error: %v",err) return } ... }

It actually prints

error: schema: invalid path "csrf.token"

Because my LoginUser{} struct doesn't have any field with form:"csrf.token" Please add a feature to ReadForm that would ignore csrf.token field and not try to fill the struct with that value I know that there's a way to fix it (add if !iris.IsErrPath(err) to the error checking or read the values one by one) but please add a fix to it Thanks

mostafa-binesh avatar Jul 30 '22 14:07 mostafa-binesh