From 67dbbd03ee9ceed8b412f2fde19bf44b3a91d2e6 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 12 Apr 2021 19:18:10 +0300 Subject: [PATCH] fix nil buf check Signed-off-by: Vasiliy Tolstov --- toml.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/toml.go b/toml.go index fbfb4fe..02e8c0f 100644 --- a/toml.go +++ b/toml.go @@ -30,7 +30,7 @@ func (c *tomlCodec) Marshal(b interface{}) ([]byte, error) { } func (c *tomlCodec) Unmarshal(b []byte, v interface{}) error { - if b == nil { + if len(b) == 0 { return nil } switch m := v.(type) { @@ -56,6 +56,8 @@ func (c *tomlCodec) ReadBody(conn io.Reader, b interface{}) error { buf, err := ioutil.ReadAll(conn) if err != nil { return err + } else if len(buf) { + return nil } m.Data = buf return nil @@ -64,7 +66,7 @@ func (c *tomlCodec) 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 { return nil }