Skip to content

Commit

Permalink
config/supermicro: Enforce ISO-8859-1/UTF-8 XML decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
splaspood committed Jun 3, 2024
1 parent 22ec803 commit 2e16d80
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion config/supermicro.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package config

import (
"bytes"
"encoding/xml"
"strings"

"golang.org/x/net/html/charset"
)

const (
Expand Down Expand Up @@ -122,7 +125,16 @@ func (cm *supermicroVendorConfig) Marshal() (string, error) {
}

func (cm *supermicroVendorConfig) Unmarshal(cfgData string) (err error) {
err = xml.Unmarshal([]byte(cfgData), cm.ConfigData)
// the xml exported by sum is ISO-8859-1 encoded
decoder := xml.NewDecoder(bytes.NewReader([]byte(cfgData)))
// convert characters from non-UTF-8 to UTF-8
decoder.CharsetReader = charset.NewReaderLabel

err = decoder.Decode(cm.ConfigData)
if err != nil {
return err
}

return
}

Expand Down

0 comments on commit 2e16d80

Please sign in to comment.