encoding/xml: rewrite invalid code points to U+FFFD in Marshal, Escape

Fixes #4235.

R=rsc, dave, r, dr.volker.dobler
CC=golang-dev
https://golang.org/cl/7438051
This commit is contained in:
Olivier Saingre 2013-03-13 23:26:03 -04:00 committed by Russ Cox
parent e778f93022
commit f74eb6dbf7
2 changed files with 28 additions and 5 deletions

View file

@ -5,6 +5,7 @@
package xml
import (
"bytes"
"fmt"
"io"
"reflect"
@ -695,6 +696,21 @@ func TestEscapeTextIOErrors(t *testing.T) {
err := EscapeText(errWriter{}, []byte{'A'})
if err == nil || err.Error() != expectErr {
t.Errorf("EscapeTest = [error] %v, want %v", err, expectErr)
t.Errorf("have %v, want %v", err, expectErr)
}
}
func TestEscapeTextInvalidChar(t *testing.T) {
input := []byte("A \x00 terminated string.")
expected := "A \uFFFD terminated string."
buff := new(bytes.Buffer)
if err := EscapeText(buff, input); err != nil {
t.Fatalf("have %v, want nil", err)
}
text := buff.String()
if text != expected {
t.Errorf("have %v, want %v", text, expected)
}
}