diff options
| author | Dominik Honnef <dominik.honnef@gmail.com> | 2013-08-19 10:14:10 +1000 |
|---|---|---|
| committer | Andrew Gerrand <adg@golang.org> | 2013-08-19 10:14:10 +1000 |
| commit | 43a39bfd7fde223b741fc05ee5ac8a336e2a8f0a (patch) | |
| tree | bec7ead0be912c48d167e4e868275772df19c07d /src/pkg/encoding | |
| parent | 7fb121aa479c96e32c1178d4c65e865ae5cb5144 (diff) | |
| download | go-43a39bfd7fde223b741fc05ee5ac8a336e2a8f0a.tar.xz | |
encoding/xml: flush buffer after encoding token
R=rsc, bradfitz, adg
CC=golang-dev
https://golang.org/cl/13004046
Diffstat (limited to 'src/pkg/encoding')
| -rw-r--r-- | src/pkg/encoding/xml/marshal.go | 3 | ||||
| -rw-r--r-- | src/pkg/encoding/xml/marshal_test.go | 9 |
2 files changed, 10 insertions, 2 deletions
diff --git a/src/pkg/encoding/xml/marshal.go b/src/pkg/encoding/xml/marshal.go index a6ee5d5128..06bdec4f73 100644 --- a/src/pkg/encoding/xml/marshal.go +++ b/src/pkg/encoding/xml/marshal.go @@ -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 { diff --git a/src/pkg/encoding/xml/marshal_test.go b/src/pkg/encoding/xml/marshal_test.go index 8d9239eb4a..31d4d4d853 100644 --- a/src/pkg/encoding/xml/marshal_test.go +++ b/src/pkg/encoding/xml/marshal_test.go @@ -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) |
