mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-03-17 13:22:56 +01:00
Changing (evt Event) MarshalJSON to avoid string escaping bug
This commit is contained in:
parent
b9d04f1496
commit
afcfa20763
@ -106,7 +106,7 @@ func fastjsonArrayToTags(v *fastjson.Value) (Tags, error) {
|
||||
}
|
||||
|
||||
// MarshalJSON() returns the JSON byte encoding of the event, as in NIP-01.
|
||||
func (evt *Event) MarshalJSON() ([]byte, error) {
|
||||
func (evt Event) MarshalJSON() ([]byte, error) {
|
||||
dst := make([]byte, 0)
|
||||
dst = append(dst, '{')
|
||||
dst = append(dst, []byte(fmt.Sprintf("\"id\":\"%s\",\"pubkey\":\"%s\",\"created_at\":%d,\"kind\":%d,\"tags\":",
|
||||
|
10
relay.go
10
relay.go
@ -229,15 +229,7 @@ func (r *Relay) Publish(ctx context.Context, event Event) Status {
|
||||
defer r.okCallbacks.Delete(event.ID)
|
||||
|
||||
// publish event
|
||||
message := []byte("[\"EVENT\",")
|
||||
if m, e := event.MarshalJSON(); e == nil {
|
||||
message = append(message, m...)
|
||||
message = append(message, ']')
|
||||
} else {
|
||||
return status
|
||||
}
|
||||
|
||||
if err := r.Connection.WriteMessage(websocket.TextMessage, message); err != nil {
|
||||
if err := r.Connection.WriteJSON([]interface{}{"EVENT", event}); err != nil {
|
||||
return status
|
||||
}
|
||||
|
||||
|
8
tags.go
8
tags.go
@ -12,15 +12,10 @@ type Tag []string
|
||||
|
||||
// StartsWith checks if a tag contains a prefix.
|
||||
// for example,
|
||||
//
|
||||
// ["p", "abcdef...", "wss://relay.com"]
|
||||
//
|
||||
// would match against
|
||||
//
|
||||
// ["p", "abcdef..."]
|
||||
//
|
||||
// or even
|
||||
//
|
||||
// ["p", "abcdef...", "wss://"]
|
||||
func (tag Tag) StartsWith(prefix []string) bool {
|
||||
prefixLen := len(prefix)
|
||||
@ -160,7 +155,8 @@ func (tag Tag) marshalTo(dst []byte) []byte {
|
||||
return dst
|
||||
}
|
||||
|
||||
// Marshal Tags. Used for Serialization so string escaping should be as in RFC8259.
|
||||
// MarshalTo appends the JSON encoded byte of Tags as [][]string to dst.
|
||||
// String escaping is as described in RFC8259.
|
||||
func (tags Tags) marshalTo(dst []byte) []byte {
|
||||
dst = append(dst, '[')
|
||||
for i, tag := range tags {
|
||||
|
Loading…
x
Reference in New Issue
Block a user