From e9c44893696e89cd254b1b65fb5bee3fdd6f83bc Mon Sep 17 00:00:00 2001 From: WindowsSov8forUs Date: Fri, 12 Apr 2024 14:03:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=85=83=E7=B4=A0=E7=9A=84=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=8C=96?= =?UTF-8?q?=EF=BC=8C=E5=9C=A8=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=8C=96=E6=97=B6?= =?UTF-8?q?=E5=B0=86=E5=B1=9E=E6=80=A7=E5=86=85=E5=AD=97=E7=AC=A6=E4=B8=B2?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E8=BD=AC=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/message/message_element_basic.go | 22 +++++++++++----------- pkg/message/message_element_meta.go | 10 +++++----- pkg/message/message_element_oprator.go | 12 ++++++------ pkg/message/message_element_resource.go | 8 ++++---- pkg/message/message_element_typography.go | 2 +- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/pkg/message/message_element_basic.go b/pkg/message/message_element_basic.go index 7dbceab..f494177 100644 --- a/pkg/message/message_element_basic.go +++ b/pkg/message/message_element_basic.go @@ -16,7 +16,7 @@ func (e *MessageElementText) Tag() string { } func (e *MessageElementText) Stringify() string { - return e.Content + return escape(e.Content, true) } func (e *MessageElementText) Parse(n *html.Node) (MessageElement, error) { @@ -46,18 +46,18 @@ func (e *MessageElementAt) Tag() string { func (e *MessageElementAt) Stringify() string { result := "<" + e.Tag() if e.Id != "" { - result += ` id="` + e.Id + `"` + result += ` id="` + escape(e.Id, true) + `"` } if e.Name != "" { - result += ` name="` + e.Name + `"` + result += ` name="` + escape(e.Name, true) + `"` } if e.Role != "" { - result += ` role="` + e.Role + `"` + result += ` role="` + escape(e.Role, true) + `"` } if e.Type != "" { - result += ` type="` + e.Type + `"` + result += ` type="` + escape(e.Type, true) + `"` } - return result + " />" + return result + "/>" } func (e *MessageElementAt) Parse(n *html.Node) (MessageElement, error) { @@ -83,12 +83,12 @@ func (e *MessageElementSharp) Tag() string { func (e *MessageElementSharp) Stringify() string { result := "<" + e.Tag() if e.Id != "" { - result += ` id="` + e.Id + `"` + result += ` id="` + escape(e.Id, true) + `"` } if e.Name != "" { - result += ` name="` + e.Name + `"` + result += ` name="` + escape(e.Name, true) + `"` } - return result + " />" + return result + "/>" } func (e *MessageElementSharp) Parse(n *html.Node) (MessageElement, error) { @@ -111,9 +111,9 @@ func (e *MessageElementA) Tag() string { func (e *MessageElementA) Stringify() string { result := "<" + e.Tag() if e.Href != "" { - result += ` href="` + e.Href + `"` + result += ` href="` + escape(e.Href, true) + `"` } - return result + " />" + return result + "/>" } func (e *MessageElementA) Parse(n *html.Node) (MessageElement, error) { attrMap := attrList2MapVal(n.Attr) diff --git a/pkg/message/message_element_meta.go b/pkg/message/message_element_meta.go index 1879a36..8c7c897 100644 --- a/pkg/message/message_element_meta.go +++ b/pkg/message/message_element_meta.go @@ -45,20 +45,20 @@ func (e *MessageElementAuthor) Tag() string { func (e *MessageElementAuthor) Stringify() string { result := "<" + e.Tag() if e.Id != "" { - result += ` id="` + e.Id + `"` + result += ` id="` + escape(e.Id, true) + `"` } if e.Name != "" { - result += ` name="` + e.Name + `"` + result += ` name="` + escape(e.Name, true) + `"` } if e.Avatar != "" { - result += ` avatar="` + e.Avatar + `"` + result += ` avatar="` + escape(e.Avatar, true) + `"` } // result += ">" childrenStr := e.stringifyChildren() if childrenStr == "" { - return result + ` />` + return result + `/>` } - return result + ` >` + childrenStr + `` + return result + `>` + childrenStr + `` } func (e *MessageElementAuthor) Parse(n *html.Node) (MessageElement, error) { diff --git a/pkg/message/message_element_oprator.go b/pkg/message/message_element_oprator.go index 38c38e1..515df30 100644 --- a/pkg/message/message_element_oprator.go +++ b/pkg/message/message_element_oprator.go @@ -24,21 +24,21 @@ func (e *MessageElementButton) Tag() string { func (e *MessageElementButton) Stringify() string { result := "<" + e.Tag() if e.Id != "" { - result += ` id="` + e.Id + `"` + result += ` id="` + escape(e.Id, true) + `"` } if e.Type != "" { - result += ` type="` + e.Type + `"` + result += ` type="` + escape(e.Type, true) + `"` } if e.Href != "" { - result += ` href="` + e.Href + `"` + result += ` href="` + escape(e.Href, true) + `"` } if e.Text != "" { - result += ` text="` + e.Text + `"` + result += ` text="` + escape(e.Text, true) + `"` } if e.Theme != "" { - result += ` theme="` + e.Theme + `"` + result += ` theme="` + escape(e.Theme, true) + `"` } - return result + " />" + return result + "/>" } func (e *MessageElementButton) Parse(n *html.Node) (MessageElement, error) { diff --git a/pkg/message/message_element_resource.go b/pkg/message/message_element_resource.go index edd3119..680ef74 100644 --- a/pkg/message/message_element_resource.go +++ b/pkg/message/message_element_resource.go @@ -66,7 +66,7 @@ func (e *MessageElementImg) attrString() string { } result := "" if e.Src != "" { - result += ` src="` + e.Src + `"` + result += ` src="` + escape(e.Src, true) + `"` } if e.Cache { result += ` cache` @@ -135,7 +135,7 @@ func (e *MessageElementAudio) attrString() string { } result := "" if e.Src != "" { - result += ` src="` + e.Src + `"` + result += ` src="` + escape(e.Src, true) + `"` } if e.Cache { result += ` cache` @@ -183,7 +183,7 @@ func (e *MessageElementVideo) attrString() string { } result := "" if e.Src != "" { - result += ` src="` + e.Src + `"` + result += ` src="` + escape(e.Src, true) + `"` } if e.Cache { result += ` cache` @@ -230,7 +230,7 @@ func (e *MessageElementFile) attrString() string { } result := "" if e.Src != "" { - result += ` src="` + e.Src + `"` + result += ` src="` + escape(e.Src, true) + `"` } if e.Cache { result += ` cache` diff --git a/pkg/message/message_element_typography.go b/pkg/message/message_element_typography.go index 2a00d90..4559f14 100644 --- a/pkg/message/message_element_typography.go +++ b/pkg/message/message_element_typography.go @@ -62,7 +62,7 @@ func (e *MessageElementMessage) Tag() string { func (e *MessageElementMessage) Stringify() string { result := "" if e.Id != "" { - result += ` id="` + e.Id + `"` + result += ` id="` + escape(e.Id, true) + `"` } if e.Forward { result += ` forward`