accept > 2 items on EOSE and NOTICE envelopes, but ignore them.
fixes https://github.com/nbd-wtf/go-nostr/issues/110
This commit is contained in:
16
envelopes.go
16
envelopes.go
@@ -200,13 +200,11 @@ func (_ NoticeEnvelope) Label() string { return "NOTICE" }
|
|||||||
func (v *NoticeEnvelope) UnmarshalJSON(data []byte) error {
|
func (v *NoticeEnvelope) UnmarshalJSON(data []byte) error {
|
||||||
r := gjson.ParseBytes(data)
|
r := gjson.ParseBytes(data)
|
||||||
arr := r.Array()
|
arr := r.Array()
|
||||||
switch len(arr) {
|
if len(arr) < 2 {
|
||||||
case 2:
|
|
||||||
*v = NoticeEnvelope(arr[1].Str)
|
|
||||||
return nil
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("failed to decode NOTICE envelope")
|
return fmt.Errorf("failed to decode NOTICE envelope")
|
||||||
}
|
}
|
||||||
|
*v = NoticeEnvelope(arr[1].Str)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v NoticeEnvelope) MarshalJSON() ([]byte, error) {
|
func (v NoticeEnvelope) MarshalJSON() ([]byte, error) {
|
||||||
@@ -224,13 +222,11 @@ func (_ EOSEEnvelope) Label() string { return "EOSE" }
|
|||||||
func (v *EOSEEnvelope) UnmarshalJSON(data []byte) error {
|
func (v *EOSEEnvelope) UnmarshalJSON(data []byte) error {
|
||||||
r := gjson.ParseBytes(data)
|
r := gjson.ParseBytes(data)
|
||||||
arr := r.Array()
|
arr := r.Array()
|
||||||
switch len(arr) {
|
if len(arr) < 2 {
|
||||||
case 2:
|
|
||||||
*v = EOSEEnvelope(arr[1].Str)
|
|
||||||
return nil
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("failed to decode EOSE envelope")
|
return fmt.Errorf("failed to decode EOSE envelope")
|
||||||
}
|
}
|
||||||
|
*v = EOSEEnvelope(arr[1].Str)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v EOSEEnvelope) MarshalJSON() ([]byte, error) {
|
func (v EOSEEnvelope) MarshalJSON() ([]byte, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user