Skip to content

Commit e37c951

Browse files
daveilersalexejk
authored andcommitted
decoder: Support charset transform if necessary
1 parent 3b4b8e9 commit e37c951

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

decode_response.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package xmlrpc
22

3-
import "encoding/xml"
3+
import (
4+
"bytes"
5+
"encoding/xml"
6+
7+
"golang.org/x/net/html/charset"
8+
)
49

510
// Response is the basic parsed object of the XML-RPC response body.
611
// While it's not convenient to use this object directly - it contains all the information needed to unmarshal into other data-types.
@@ -13,7 +18,9 @@ type Response struct {
1318
// It relies on XML Unmarshaler and if it fails - error is returned.
1419
func NewResponse(body []byte) (*Response, error) {
1520
response := &Response{}
16-
if err := xml.Unmarshal(body, response); err != nil {
21+
dec := xml.NewDecoder(bytes.NewReader(body))
22+
dec.CharsetReader = charset.NewReaderLabel
23+
if err := dec.Decode(response); err != nil {
1724
return nil, err
1825
}
1926

go.mod

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
module alexejk.io/go-xmlrpc
22

3-
go 1.21
3+
go 1.25.4
44

5-
require github.com/stretchr/testify v1.10.0
5+
require (
6+
github.com/stretchr/testify v1.10.0
7+
golang.org/x/net v0.46.0
8+
)
69

710
require (
811
github.com/davecgh/go-spew v1.1.1 // indirect
912
github.com/pmezard/go-difflib v1.0.0 // indirect
13+
golang.org/x/text v0.30.0 // indirect
1014
gopkg.in/yaml.v3 v3.0.1 // indirect
1115
)

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
44
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
55
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
66
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
7+
golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4=
8+
golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210=
9+
golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=
10+
golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM=
711
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
812
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
913
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

0 commit comments

Comments
 (0)