Skip to content

application/x-www-form-urlencoded 参数为空时报错 #57

@xusion

Description

@xusion

application/x-www-form-urlencoded 参数为空时报错

INFO] 2019/09/08 12:16 200 3.582027ms 127.0.0.1 POST /m/login
12:18:23 app | 2019/09/08 12:18:23 application/x-www-form-urlencoded
12:18:23 app | 2019/09/08 12:18:23 Reading form
12:18:23 app | [WARN] 2019/09/08 12:18 Recovered from a route's Handler('github.com/betacraft/yaag/irisyaag.New.func1')
At Request: 200 /m/login POST 127.0.0.1
Trace: runtime error: index out of range

/usr/local/Cellar/go/1.12.9/libexec/src/runtime/panic.go:522
/usr/local/Cellar/go/1.12.9/libexec/src/runtime/panic.go:44
/Users/xxx/go/src/github.com/betacraft/yaag/middleware/yaagmiddleware.go:139
/Users/xxx/go/src/github.com/betacraft/yaag/middleware/yaagmiddleware.go:83
/Users/xxx/go/src/github.com/betacraft/yaag/irisyaag/middleware.go:23

/Users/xxx/go/src/github.com/betacraft/yaag/middleware/yaagmiddleware.go:139
func ReadPostForm(req *http.Request) map[string]string {
postForm := map[string]string{}
for _, param := range strings.Split(*ReadBody(req), "&") {
value := strings.Split(param, "=")
postForm[value[0]] = value[1]
}
return postForm
}

加粗这一行,很明显没有判断空参数的情况。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions