From 85472a72b4bd76f204c473c4119b8b6ec20df932 Mon Sep 17 00:00:00 2001 From: Matt Goodall Date: Wed, 11 Jul 2012 15:50:27 +0100 Subject: [PATCH] Ensure all methods that decode a stanza go via the same route. --- src/xmpp/stream.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/xmpp/stream.go b/src/xmpp/stream.go index 4feb2a9..1cb4521 100644 --- a/src/xmpp/stream.go +++ b/src/xmpp/stream.go @@ -116,11 +116,21 @@ func (stream *Stream) Skip() error { // Decode the next stanza. Works like xml.Unmarshal but reads from the stream's // connection. func (stream *Stream) Decode(v interface{}) error { - return stream.dec.Decode(v) + return stream.DecodeElement(v, nil) } // Decode the stanza with the given start element. Works like // xml.Decoder.DecodeElement. func (stream *Stream) DecodeElement(v interface{}, start *xml.StartElement) error { + + // Explicity lookup next start element to ensure stream is validated. + if start == nil { + if se, err := stream.Next(nil); err != nil { + return err + } else { + start = se + } + } + return stream.dec.DecodeElement(v, start) }