From c64ebde59d319dfce9d73333908deaf910599267 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Fri, 14 Mar 2025 20:08:56 -0300 Subject: [PATCH] fix sonic parsing req envelopes with limit/since/until. --- envelopes_sonic.go | 3 +++ envelopes_test.go | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/envelopes_sonic.go b/envelopes_sonic.go index 43c8c5a..4cabcbc 100644 --- a/envelopes_sonic.go +++ b/envelopes_sonic.go @@ -447,10 +447,13 @@ func (sv *sonicVisitor) OnInt64(v int64, _ stdlibjson.Number) error { case inLimit: sv.currentFilter.Limit = int(v) sv.currentFilter.LimitZero = v == 0 + sv.whereWeAre = inFilterObject case inSince: sv.currentFilter.Since = (*Timestamp)(&v) + sv.whereWeAre = inFilterObject case inUntil: sv.currentFilter.Until = (*Timestamp)(&v) + sv.whereWeAre = inFilterObject case inKinds: sv.currentFilter.Kinds = append(sv.currentFilter.Kinds, int(v)) diff --git a/envelopes_test.go b/envelopes_test.go index b9e54e8..01092a4 100644 --- a/envelopes_test.go +++ b/envelopes_test.go @@ -106,6 +106,16 @@ func TestParseMessage(t *testing.T) { Message: `["CLOSE","subscription123"]`, ExpectedEnvelope: ptr(CloseEnvelope("subscription123")), }, + { + Name: "AUTH envelope from nak 23gmt bug", + Message: `["AUTH","c45b2b06ad92e28a"]`, + ExpectedEnvelope: &AuthEnvelope{Challenge: ptr("c45b2b06ad92e28a")}, + }, + { + Name: "REQ from jumble", + Message: `["REQ","sub:1",{"kinds":[1,6],"limit":100}]`, + ExpectedEnvelope: &ReqEnvelope{SubscriptionID: "sub:1", Filters: Filters{{Kinds: []int{1, 6}, Limit: 100}}}, + }, } t.Run("standard", func(t *testing.T) {