From 127e75bc8ba3522c5f45a19d64958c6dc8a10558 Mon Sep 17 00:00:00 2001 From: Martin Hebnes Pedersen Date: Fri, 3 Nov 2017 13:12:33 +0100 Subject: [PATCH] Fix neglected io.EOF handling This was probably catched in most cases after commit 9dd92e1, but was at best misleading as it suggested that the end of input stream signal from xml.Decoder was intentionally ignored. Ref mattn/go-xmpp#28 --- xmpp.go | 2 +- xmpp_test.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/xmpp.go b/xmpp.go index 3666d0a..6af9a3e 100644 --- a/xmpp.go +++ b/xmpp.go @@ -833,7 +833,7 @@ type rosterItem struct { func nextStart(p *xml.Decoder) (xml.StartElement, error) { for { t, err := p.Token() - if err != nil && err != io.EOF || t == nil { + if err != nil || t == nil { return xml.StartElement{}, err } switch t := t.(type) { diff --git a/xmpp_test.go b/xmpp_test.go index 51f02eb..3496d4e 100644 --- a/xmpp_test.go +++ b/xmpp_test.go @@ -3,6 +3,7 @@ package xmpp import ( "bytes" "encoding/xml" + "io" "net" "reflect" "strings" @@ -103,3 +104,13 @@ func TestStanzaError(t *testing.T) { t.Errorf("Recv() = %#v; want %#v", v, chat) } } + +func TestEOFError(t *testing.T) { + var c Client + c.conn = tConnect("") + c.p = xml.NewDecoder(c.conn) + _, err := c.Recv() + if err != io.EOF { + t.Errorf("Recv() did not return io.EOF on end of input stream") + } +}