diff --git a/coolq/cqcode.go b/coolq/cqcode.go index 08f9fd6..e15305f 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -1,9 +1,11 @@ package coolq import ( + "bytes" "crypto/md5" "encoding/base64" "encoding/hex" + xml2 "encoding/xml" "errors" "fmt" "github.com/Mrs4s/MiraiGo/binary" @@ -568,7 +570,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf }}, nil } xml := fmt.Sprintf(``, - url.PathEscape(d["title"]), d["url"], d["image"], d["audio"], url.PathEscape(d["title"]), url.PathEscape(d["content"])) + XmlEscape(d["title"]), d["url"], d["image"], d["audio"], XmlEscape(d["title"]), XmlEscape(d["content"])) return &message.ServiceElement{ Id: 60, Content: xml, @@ -625,6 +627,12 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf return nil, nil } +func XmlEscape(c string) string { + buf := new(bytes.Buffer) + _ = xml2.EscapeText(buf, []byte(c)) + return buf.String() +} + func CQCodeEscapeText(raw string) string { ret := raw ret = strings.ReplaceAll(ret, "&", "&")