aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/pkg/xml/marshal.go2
-rw-r--r--src/pkg/xml/marshal_test.go6
2 files changed, 7 insertions, 1 deletions
diff --git a/src/pkg/xml/marshal.go b/src/pkg/xml/marshal.go
index f6e5bf5cdb..ea421c1b17 100644
--- a/src/pkg/xml/marshal.go
+++ b/src/pkg/xml/marshal.go
@@ -177,7 +177,7 @@ func (p *printer) marshalValue(val reflect.Value, name string) os.Error {
case "":
case "chardata":
if tk := f.Type.Kind(); tk == reflect.String {
- p.Write([]byte(val.Field(i).String()))
+ Escape(p, []byte(val.Field(i).String()))
} else if tk == reflect.Slice {
if elem, ok := val.Field(i).Interface().([]byte); ok {
Escape(p, elem)
diff --git a/src/pkg/xml/marshal_test.go b/src/pkg/xml/marshal_test.go
index 77b2e726d5..5b972fafe6 100644
--- a/src/pkg/xml/marshal_test.go
+++ b/src/pkg/xml/marshal_test.go
@@ -57,6 +57,11 @@ type Domain struct {
Name []byte `xml:"chardata"`
}
+type Book struct {
+ XMLName Name `xml:"book"`
+ Title string `xml:"chardata"`
+}
+
type SecretAgent struct {
XMLName Name `xml:"agent"`
Handle string `xml:"attr"`
@@ -113,6 +118,7 @@ var marshalTests = []struct {
{Value: &Port{Number: "443"}, ExpectXML: `<port>443</port>`},
{Value: &Port{Type: "<unix>"}, ExpectXML: `<port type="&lt;unix&gt;"></port>`},
{Value: &Domain{Name: []byte("google.com&friends")}, ExpectXML: `<domain>google.com&amp;friends</domain>`},
+ {Value: &Book{Title: "Pride & Prejudice"}, ExpectXML: `<book>Pride &amp; Prejudice</book>`},
{Value: atomValue, ExpectXML: atomXml},
{
Value: &Ship{