File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -39,6 +39,12 @@ func TextConsumer() Consumer {
3939 }
4040 b := buf .Bytes ()
4141
42+ // If the buffer is empty, no need to unmarshal it, which causes a panic.
43+ if len (b ) == 0 {
44+ data = ""
45+ return nil
46+ }
47+
4248 if tu , ok := data .(encoding.TextUnmarshaler ); ok {
4349 err := tu .UnmarshalText (b )
4450 if err != nil {
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ func TestTextConsumer(t *testing.T) {
4343 assert .Equal (t , consProdText , tu .str )
4444
4545 // text unmarshal objects can return an error as well, this will be propagated
46- assert .Error (t , cons .Consume (bytes .NewBuffer (nil ), & tu ))
46+ assert .NoError (t , cons .Consume (bytes .NewBuffer (nil ), & tu ))
4747
4848 // when readers can't be read, those errors will be propogated as well
4949 assert .Error (t , cons .Consume (new (nopReader ), & tu ))
You can’t perform that action at this time.
0 commit comments