修复当xml中不包含encoding时报错的问题

This commit is contained in:
wenzi1
2018-07-04 11:17:15 +08:00
parent 667bd0efa5
commit 27733ce7ff

View File

@ -61,10 +61,15 @@ func prepare(xmlbyte []byte) error {
if err != nil {
return err
}
xmlEncode := "UTF-8"
if len(matchStr) == 2 {
xmlEncode = matchStr[1]
}
charset := mahonia.GetCharset(matchStr[1])
charset := mahonia.GetCharset(xmlEncode)
if charset == nil {
return errors.New(fmt.Sprintf("not support charset:%s", matchStr[1]))
return errors.New(fmt.Sprintf("not support charset:%s", xmlEncode))
}
if !strings.EqualFold(charset.Name, "UTF-8") {