Merge pull request #92 from amia-as/fix/neglected-eof-error

Fix neglected io.EOF handling
This commit is contained in:
mattn 2017-11-07 14:16:34 +09:00 committed by GitHub
commit d0cdb99fae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -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) {

View File

@ -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")
}
}