Skip to content

Commit

Permalink
accept > 2 items on EOSE and NOTICE envelopes, but ignore them.
Browse files Browse the repository at this point in the history
fixes #110
  • Loading branch information
fiatjaf committed Nov 14, 2023
1 parent 93b43ed commit 9287b9f
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions envelopes.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,11 @@ func (_ NoticeEnvelope) Label() string { return "NOTICE" }
func (v *NoticeEnvelope) UnmarshalJSON(data []byte) error {
r := gjson.ParseBytes(data)
arr := r.Array()
switch len(arr) {
case 2:
*v = NoticeEnvelope(arr[1].Str)
return nil
default:
if len(arr) < 2 {
return fmt.Errorf("failed to decode NOTICE envelope")
}
*v = NoticeEnvelope(arr[1].Str)
return nil
}

func (v NoticeEnvelope) MarshalJSON() ([]byte, error) {
Expand All @@ -224,13 +222,11 @@ func (_ EOSEEnvelope) Label() string { return "EOSE" }
func (v *EOSEEnvelope) UnmarshalJSON(data []byte) error {
r := gjson.ParseBytes(data)
arr := r.Array()
switch len(arr) {
case 2:
*v = EOSEEnvelope(arr[1].Str)
return nil
default:
if len(arr) < 2 {
return fmt.Errorf("failed to decode EOSE envelope")
}
*v = EOSEEnvelope(arr[1].Str)
return nil
}

func (v EOSEEnvelope) MarshalJSON() ([]byte, error) {
Expand Down

0 comments on commit 9287b9f

Please sign in to comment.