fix sonic parsing req envelopes with limit/since/until.

This commit is contained in:
fiatjaf 2025-03-14 20:08:56 -03:00
parent 4dcadd4d88
commit c64ebde59d
2 changed files with 13 additions and 0 deletions

View File

@ -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))

View File

@ -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) {