-
Notifications
You must be signed in to change notification settings - Fork 177
Expand file tree
/
Copy pathconfig_xml.go
More file actions
34 lines (30 loc) · 1002 Bytes
/
Copy pathconfig_xml.go
File metadata and controls
34 lines (30 loc) · 1002 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package config
import (
"bytes"
"encoding/xml"
)
// UnmarshalXML parses the XML-encoded data and stores the result in
// the value pointed to by v, which must be an arbitrary struct,
// slice, or string. Well-formed data that does not fit into v is
// discarded.
//
// Security: This function uses xml.Decoder with strict settings to prevent
// XXE (XML External Entity) attacks.
func UnmarshalXML(content []byte, v interface{}) error {
decoder := xml.NewDecoder(bytes.NewReader(content))
// Note: Go's xml package doesn't process external entities by default
// This explicit usage of Decoder provides clarity and future-proofing
return decoder.Decode(v)
}
// MarshalXML returns the XML encoding of v.
func MarshalXML(v interface{}) (out []byte, err error) {
return xml.Marshal(v)
}
// MarshalXMLString returns the XML encoding string format of v.
func MarshalXMLString(v interface{}) (out string) {
marshal, err := xml.Marshal(v)
if err != nil {
return ""
}
return string(marshal)
}