Skip to content

Commit

Permalink
remove HTML escaping from (easy)json encoder everywhere.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed Nov 12, 2024
1 parent b62678e commit a0bf181
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
18 changes: 9 additions & 9 deletions envelopes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 + `",`)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(`]`)
Expand All @@ -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(`]`)
Expand Down Expand Up @@ -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(`]`)
Expand Down Expand Up @@ -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(`,`)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion event_easyjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
3 changes: 2 additions & 1 deletion filter_easyjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion nip77/envelopes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit a0bf181

Please sign in to comment.