fix: 推送 meta 用 UseNumber 保留超过 2^53 的整数
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package message
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
@@ -742,3 +743,37 @@ func TestPushRevokedOnRecallAfterPush(t *testing.T) {
|
||||
t.Fatal("expected revoked frame")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPushPreservesLargeMetaInteger(t *testing.T) {
|
||||
t.Parallel()
|
||||
raw := `{"id":12345678901234567890}`
|
||||
decoded := decodeMetaJSON(raw)
|
||||
n, ok := decoded["id"].(json.Number)
|
||||
if !ok || n.String() != "12345678901234567890" {
|
||||
t.Fatalf("decode meta=%v", decoded)
|
||||
}
|
||||
|
||||
e := openDeliveryEnv(t, nil)
|
||||
insertEndpoint(t, e.db, "alice", "", 1, 0)
|
||||
insertEndpoint(t, e.db, "bob", "", 1, 0)
|
||||
e.online("bob", "c-bob")
|
||||
ctx := context.Background()
|
||||
req := baseSend("meta-big", "bob")
|
||||
req.Meta = map[string]any{"id": json.Number("12345678901234567890")}
|
||||
if _, err := e.app.Submit(ctx, "alice", port.ConnInfo{}, req); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := e.app.PushPending(ctx, "bob", "c-bob"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
found := false
|
||||
for _, p := range e.down.Snapshots() {
|
||||
if bytes.Contains(p.Payload, []byte("12345678901234567890")) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("push payloads missing large int: %v", e.down.Snapshots())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package message
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
|
||||
"git.asio.asia/nixevol/NixMsg/internal/protocol"
|
||||
)
|
||||
@@ -94,7 +93,7 @@ func (a *App) dispatchFullTx(tx *sql.Tx, seq int64, senderID, destKind, destID s
|
||||
SELECT gm.endpoint_id, e.enabled
|
||||
FROM group_members gm
|
||||
JOIN endpoints e ON e.id = gm.endpoint_id
|
||||
WHERE gm.group_id = ? AND gm.endpoint_id != ?`, destID, senderID)
|
||||
WHERE gm.group_id = ? AND gm.endpoint_id != ? AND gm.joined_at <= ?`, destID, senderID, sendAt)
|
||||
if qErr != nil {
|
||||
return "", true, qErr
|
||||
}
|
||||
@@ -342,7 +341,7 @@ func decodeMetaJSON(s string) map[string]any {
|
||||
return nil
|
||||
}
|
||||
var m map[string]any
|
||||
if err := json.Unmarshal([]byte(s), &m); err != nil {
|
||||
if err := protocol.Unmarshal([]byte(s), &m); err != nil {
|
||||
return nil
|
||||
}
|
||||
return m
|
||||
|
||||
Reference in New Issue
Block a user