mirror of
https://github.com/golang/go
synced 2024-11-22 04:14:42 -07:00
encoding/xml: flush buffer after encoding token
R=rsc, bradfitz, adg CC=golang-dev https://golang.org/cl/13004046
This commit is contained in:
parent
7fb121aa47
commit
43a39bfd7f
@ -196,7 +196,6 @@ func (enc *Encoder) EncodeToken(t Token) error {
|
|||||||
p.WriteString("<!--")
|
p.WriteString("<!--")
|
||||||
p.Write(t)
|
p.Write(t)
|
||||||
p.WriteString("-->")
|
p.WriteString("-->")
|
||||||
return p.cachedWriteError()
|
|
||||||
case ProcInst:
|
case ProcInst:
|
||||||
if t.Target == "xml" || !isNameString(t.Target) {
|
if t.Target == "xml" || !isNameString(t.Target) {
|
||||||
return fmt.Errorf("xml: EncodeToken of ProcInst with invalid 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.Write(t)
|
||||||
p.WriteString(">")
|
p.WriteString(">")
|
||||||
}
|
}
|
||||||
return p.cachedWriteError()
|
return p.Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
type printer struct {
|
type printer struct {
|
||||||
|
@ -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) {
|
func BenchmarkMarshal(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
Marshal(atomValue)
|
Marshal(atomValue)
|
||||||
|
Loading…
Reference in New Issue
Block a user