Skip to content

Commit

Permalink
Issue: #1917 in github.com/go-swagger/go-swagger: Don't attempt to un…
Browse files Browse the repository at this point in the history
…marshal empty response bodies to prevent panic.

Signed-off-by: jwalter1-quest <jeff.walter@quest.com>
  • Loading branch information
jwalter1-quest committed Apr 11, 2019
1 parent 1097371 commit 65735b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions text.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ func TextConsumer() Consumer {
}
b := buf.Bytes()

// If the buffer is empty, no need to unmarshal it, which causes a panic.
if len(b) == 0 {
data = ""
return nil
}

if tu, ok := data.(encoding.TextUnmarshaler); ok {
err := tu.UnmarshalText(b)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestTextConsumer(t *testing.T) {
assert.Equal(t, consProdText, tu.str)

// text unmarshal objects can return an error as well, this will be propagated
assert.Error(t, cons.Consume(bytes.NewBuffer(nil), &tu))
assert.NoError(t, cons.Consume(bytes.NewBuffer(nil), &tu))

// when readers can't be read, those errors will be propogated as well
assert.Error(t, cons.Consume(new(nopReader), &tu))
Expand Down

0 comments on commit 65735b4

Please sign in to comment.