From cb9e554fc9e77c9f6fe0b32eae7fba7eb11fcb0b Mon Sep 17 00:00:00 2001 From: 1l0 Date: Mon, 13 Jan 2025 14:41:07 +0900 Subject: [PATCH] nip22: prevent panic, return nil if not found according to nip10.go --- connection_options_js.go | 2 +- go.mod | 3 --- go.sum | 6 ------ nip22/nip22.go | 13 ++++++++----- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/connection_options_js.go b/connection_options_js.go index f40ec86..3e80025 100644 --- a/connection_options_js.go +++ b/connection_options_js.go @@ -9,7 +9,7 @@ import ( var emptyOptions = ws.DialOptions{} -func getConnectionOptions(requestHeader http.Header, tlsConfig *tls.Config) *ws.DialOptions { +func getConnectionOptions(_ http.Header, _ *tls.Config) *ws.DialOptions { // on javascript we ignore everything because there is nothing else we can do return &emptyOptions } diff --git a/go.mod b/go.mod index f6e762f..8873dab 100644 --- a/go.mod +++ b/go.mod @@ -10,8 +10,6 @@ require ( github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 github.com/dgraph-io/ristretto v1.0.0 github.com/fiatjaf/eventstore v0.9.0 - github.com/gobwas/httphead v0.1.0 - github.com/gobwas/ws v1.4.0 github.com/gomarkdown/markdown v0.0.0-20241205020045-f7e15b2f3e62 github.com/graph-gophers/dataloader/v7 v7.1.0 github.com/jmoiron/sqlx v1.3.5 @@ -43,7 +41,6 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/decred/dcrd/crypto/blake256 v1.1.0 // indirect github.com/dustin/go-humanize v1.0.1 // indirect - github.com/gobwas/pool v0.2.1 // indirect github.com/google/uuid v1.6.0 // indirect github.com/gorilla/css v1.0.1 // indirect github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect diff --git a/go.sum b/go.sum index e8fd669..b940332 100644 --- a/go.sum +++ b/go.sum @@ -64,12 +64,6 @@ github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4 github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= -github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU= -github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM= -github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og= -github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= -github.com/gobwas/ws v1.4.0 h1:CTaoG1tojrh4ucGPcoJFiAQUAsEWekEWvLy7GsVNqGs= -github.com/gobwas/ws v1.4.0/go.mod h1:G3gNqMNtPppf5XUz7O4shetPpcZ1VJ7zt18dlUeakrc= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= diff --git a/nip22/nip22.go b/nip22/nip22.go index 2206eb7..863d0ef 100644 --- a/nip22/nip22.go +++ b/nip22/nip22.go @@ -4,21 +4,24 @@ import "github.com/nbd-wtf/go-nostr" func GetThreadRoot(tags nostr.Tags) *nostr.Tag { for _, tag := range tags { + if len(tag) < 2 { + continue + } if tag[0] == "E" || tag[0] == "A" || tag[0] == "I" { return &tag } } - empty := nostr.Tag{} - return &empty + return nil } func GetImmediateReply(tags nostr.Tags) *nostr.Tag { for _, tag := range tags { + if len(tag) < 2 { + continue + } if tag[0] == "e" || tag[0] == "a" || tag[0] == "i" { return &tag } } - - empty := nostr.Tag{} - return &empty + return nil }