fix: check obj type in protobufBinding (#2851)

* fix: check obj type in protobufBinding

* fix: UnitTest for invalid proto obj
This commit is contained in:
Tevic
2021-09-07 10:10:32 +08:00
committed by GitHub
parent deb83b6365
commit eab47b5423
2 changed files with 13 additions and 1 deletions
+6 -1
View File
@@ -5,6 +5,7 @@
package binding
import (
"errors"
"io/ioutil"
"net/http"
@@ -26,7 +27,11 @@ func (b protobufBinding) Bind(req *http.Request, obj interface{}) error {
}
func (protobufBinding) BindBody(body []byte, obj interface{}) error {
if err := proto.Unmarshal(body, obj.(proto.Message)); err != nil {
msg, ok := obj.(proto.Message)
if !ok {
return errors.New("obj is not ProtoMessage")
}
if err := proto.Unmarshal(body, msg); err != nil {
return err
}
// Here it's same to return validate(obj), but util now we can't add