From b94e829776a8056f8ae4fd5d95fcd3b0b5cc9f59 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 12 Apr 2021 19:20:17 +0300 Subject: [PATCH] fix nil buf check Signed-off-by: Vasiliy Tolstov --- yaml.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/yaml.go b/yaml.go index c3aae71..82f8906 100644 --- a/yaml.go +++ b/yaml.go @@ -23,7 +23,7 @@ func (c *yamlCodec) Marshal(b interface{}) ([]byte, error) { } func (c *yamlCodec) Unmarshal(b []byte, v interface{}) error { - if b == nil { + if len(b) == 0 { return nil } switch m := v.(type) { @@ -49,6 +49,8 @@ func (c *yamlCodec) ReadBody(conn io.Reader, b interface{}) error { buf, err := ioutil.ReadAll(conn) if err != nil { return err + } else if len(buf) == 0 { + return nil } m.Data = buf return nil @@ -57,7 +59,7 @@ func (c *yamlCodec) ReadBody(conn io.Reader, b interface{}) error { buf, err := ioutil.ReadAll(conn) if err != nil { return err - } else if buf == nil { + } else if len(buf) == 0 { // not needed but similar changes in all codecs return nil }