@@ -91,7 +91,25 @@ func initDefaultMap() {
91
91
defaultMap .RegisterType (& Type {Name : "varchar" , OID : VarcharOID , Codec : TextCodec {}})
92
92
defaultMap .RegisterType (& Type {Name : "xid" , OID : XIDOID , Codec : Uint32Codec {}})
93
93
defaultMap .RegisterType (& Type {Name : "xid8" , OID : XID8OID , Codec : Uint64Codec {}})
94
- defaultMap .RegisterType (& Type {Name : "xml" , OID : XMLOID , Codec : & XMLCodec {Marshal : xml .Marshal , Unmarshal : xml .Unmarshal }})
94
+ defaultMap .RegisterType (& Type {Name : "xml" , OID : XMLOID , Codec : & XMLCodec {
95
+ Marshal : xml .Marshal ,
96
+ // xml.Unmarshal does not support unmarshalling into *any. However, XMLCodec.DecodeValue calls Unmarshal with a
97
+ // *any. Wrap xml.Marshal with a function that copies the data into a new byte slice in this case. Not implementing
98
+ // directly in XMLCodec.DecodeValue to allow for the unlikely possibility that someone uses an alternative XML
99
+ // unmarshaler that does support unmarshalling into *any.
100
+ //
101
+ // https://github.com/jackc/pgx/issues/2227
102
+ // https://github.com/jackc/pgx/pull/2228
103
+ Unmarshal : func (data []byte , v any ) error {
104
+ if v , ok := v .(* any ); ok {
105
+ dstBuf := make ([]byte , len (data ))
106
+ copy (dstBuf , data )
107
+ * v = dstBuf
108
+ return nil
109
+ }
110
+ return xml .Unmarshal (data , v )
111
+ },
112
+ }})
95
113
96
114
// Range types
97
115
defaultMap .RegisterType (& Type {Name : "daterange" , OID : DaterangeOID , Codec : & RangeCodec {ElementType : defaultMap .oidToType [DateOID ]}})
0 commit comments