]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/xml: flush buffer after encoding token
authorDominik Honnef <dominik.honnef@gmail.com>
Mon, 19 Aug 2013 00:14:10 +0000 (10:14 +1000)
committerAndrew Gerrand <adg@golang.org>
Mon, 19 Aug 2013 00:14:10 +0000 (10:14 +1000)
R=rsc, bradfitz, adg
CC=golang-dev
https://golang.org/cl/13004046

src/pkg/encoding/xml/marshal.go
src/pkg/encoding/xml/marshal_test.go

index a6ee5d51285b729ec307f8fc7e927e5f666b3175..06bdec4f739c9dc4caf4920d756a7b7829f5a149 100644 (file)
@@ -196,7 +196,6 @@ func (enc *Encoder) EncodeToken(t Token) error {
                p.WriteString("<!--")
                p.Write(t)
                p.WriteString("-->")
-               return p.cachedWriteError()
        case ProcInst:
                if t.Target == "xml" || !isNameString(t.Target) {
                        return fmt.Errorf("xml: EncodeToken of ProcInst with invalid Target")
@@ -219,7 +218,7 @@ func (enc *Encoder) EncodeToken(t Token) error {
                p.Write(t)
                p.WriteString(">")
        }
-       return p.cachedWriteError()
+       return p.Flush()
 }
 
 type printer struct {
index 8d9239eb4adcf92e9c45c611346f90f02c983788..31d4d4d853fe1d09370aef46f3f984b8aa920ca5 100644 (file)
@@ -1076,6 +1076,15 @@ func TestMarshalWriteIOErrors(t *testing.T) {
        }
 }
 
+func TestEncodeTokenFlush(t *testing.T) {
+       var buf bytes.Buffer
+       enc := NewEncoder(&buf)
+       enc.EncodeToken(StartElement{Name: Name{Local: "some-tag"}})
+       if g, w := buf.String(), "<some-tag>"; g != w {
+               t.Errorf("Encoder wrote %q, want %q", g, w)
+       }
+}
+
 func BenchmarkMarshal(b *testing.B) {
        for i := 0; i < b.N; i++ {
                Marshal(atomValue)