mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
e778f93022
commit
f74eb6dbf7
2 changed files with 28 additions and 5 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue