From a0bf1815476177786923f988ff887e798d544167 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Mon, 11 Nov 2024 22:55:07 -0300 Subject: [PATCH] remove HTML escaping from (easy)json encoder everywhere. --- envelopes.go | 18 +++++++++--------- event_easyjson.go | 3 ++- filter_easyjson.go | 3 ++- nip77/envelopes.go | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/envelopes.go b/envelopes.go index 54f3f51..eec494c 100644 --- a/envelopes.go +++ b/envelopes.go @@ -91,7 +91,7 @@ func (v *EventEnvelope) UnmarshalJSON(data []byte) error { } func (v EventEnvelope) MarshalJSON() ([]byte, error) { - w := jwriter.Writer{} + w := jwriter.Writer{NoEscapeHTML: true} w.RawString(`["EVENT",`) if v.SubscriptionID != nil { w.RawString(`"` + *v.SubscriptionID + `",`) @@ -128,7 +128,7 @@ func (v *ReqEnvelope) UnmarshalJSON(data []byte) error { } func (v ReqEnvelope) MarshalJSON() ([]byte, error) { - w := jwriter.Writer{} + w := jwriter.Writer{NoEscapeHTML: true} w.RawString(`["REQ",`) w.RawString(`"` + v.SubscriptionID + `"`) for _, filter := range v.Filters { @@ -183,7 +183,7 @@ func (v *CountEnvelope) UnmarshalJSON(data []byte) error { } func (v CountEnvelope) MarshalJSON() ([]byte, error) { - w := jwriter.Writer{} + w := jwriter.Writer{NoEscapeHTML: true} w.RawString(`["COUNT",`) w.RawString(`"` + v.SubscriptionID + `"`) if v.Count != nil { @@ -219,7 +219,7 @@ func (v *NoticeEnvelope) UnmarshalJSON(data []byte) error { } func (v NoticeEnvelope) MarshalJSON() ([]byte, error) { - w := jwriter.Writer{} + w := jwriter.Writer{NoEscapeHTML: true} w.RawString(`["NOTICE",`) w.Raw(json.Marshal(string(v))) w.RawString(`]`) @@ -245,7 +245,7 @@ func (v *EOSEEnvelope) UnmarshalJSON(data []byte) error { } func (v EOSEEnvelope) MarshalJSON() ([]byte, error) { - w := jwriter.Writer{} + w := jwriter.Writer{NoEscapeHTML: true} w.RawString(`["EOSE",`) w.Raw(json.Marshal(string(v))) w.RawString(`]`) @@ -273,7 +273,7 @@ func (v *CloseEnvelope) UnmarshalJSON(data []byte) error { } func (v CloseEnvelope) MarshalJSON() ([]byte, error) { - w := jwriter.Writer{} + w := jwriter.Writer{NoEscapeHTML: true} w.RawString(`["CLOSE",`) w.Raw(json.Marshal(string(v))) w.RawString(`]`) @@ -304,7 +304,7 @@ func (v *ClosedEnvelope) UnmarshalJSON(data []byte) error { } func (v ClosedEnvelope) MarshalJSON() ([]byte, error) { - w := jwriter.Writer{} + w := jwriter.Writer{NoEscapeHTML: true} w.RawString(`["CLOSED",`) w.Raw(json.Marshal(string(v.SubscriptionID))) w.RawString(`,`) @@ -339,7 +339,7 @@ func (v *OKEnvelope) UnmarshalJSON(data []byte) error { } func (v OKEnvelope) MarshalJSON() ([]byte, error) { - w := jwriter.Writer{} + w := jwriter.Writer{NoEscapeHTML: true} w.RawString(`["OK",`) w.RawString(`"` + v.EventID + `",`) ok := "false" @@ -379,7 +379,7 @@ func (v *AuthEnvelope) UnmarshalJSON(data []byte) error { } func (v AuthEnvelope) MarshalJSON() ([]byte, error) { - w := jwriter.Writer{} + w := jwriter.Writer{NoEscapeHTML: true} w.RawString(`["AUTH",`) if v.Challenge != nil { w.Raw(json.Marshal(*v.Challenge)) diff --git a/event_easyjson.go b/event_easyjson.go index 01959f7..c1db59f 100644 --- a/event_easyjson.go +++ b/event_easyjson.go @@ -169,13 +169,14 @@ func easyjsonF642ad3eEncodeGithubComNbdWtfGoNostr(out *jwriter.Writer, in Event) // MarshalJSON supports json.Marshaler interface func (v Event) MarshalJSON() ([]byte, error) { - w := jwriter.Writer{} + w := jwriter.Writer{NoEscapeHTML: true} easyjsonF642ad3eEncodeGithubComNbdWtfGoNostr(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v Event) MarshalEasyJSON(w *jwriter.Writer) { + w.NoEscapeHTML = true easyjsonF642ad3eEncodeGithubComNbdWtfGoNostr(w, v) } diff --git a/filter_easyjson.go b/filter_easyjson.go index 4880d8a..2d30f51 100644 --- a/filter_easyjson.go +++ b/filter_easyjson.go @@ -288,13 +288,14 @@ func easyjson4d398eaaEncodeGithubComNbdWtfGoNostr(out *jwriter.Writer, in Filter // MarshalJSON supports json.Marshaler interface func (v Filter) MarshalJSON() ([]byte, error) { - w := jwriter.Writer{} + w := jwriter.Writer{NoEscapeHTML: true} easyjson4d398eaaEncodeGithubComNbdWtfGoNostr(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v Filter) MarshalEasyJSON(w *jwriter.Writer) { + w.NoEscapeHTML = true easyjson4d398eaaEncodeGithubComNbdWtfGoNostr(w, v) } diff --git a/nip77/envelopes.go b/nip77/envelopes.go index 4f48c29..b870c57 100644 --- a/nip77/envelopes.go +++ b/nip77/envelopes.go @@ -75,7 +75,7 @@ func (v OpenEnvelope) MarshalJSON() ([]byte, error) { res.WriteString(v.SubscriptionID) res.WriteString(`",`) - w := jwriter.Writer{} + w := jwriter.Writer{NoEscapeHTML: true} v.Filter.MarshalEasyJSON(&w) w.Buffer.DumpTo(res)