Skip to content

Commit ef2373e

Browse files
committed
fix: skip invalid stored reactions
1 parent 2963ffb commit ef2373e

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

pkg/connector/reaction.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ func storedLineReactionForMatrixKey(key string, reactions []*database.Reaction)
548548
}
549549
ref, err := newLineReactionRef(meta.ReactionType)
550550
if err != nil || (reaction.EmojiID != "" && reaction.EmojiID != ref.networkEmojiID()) {
551-
return lineReactionRef{}, false
551+
continue
552552
}
553553
if hasFound && !found.equal(ref) {
554554
return lineReactionRef{}, false

pkg/connector/reaction_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,21 @@ func TestStoredLineReactionForMatrixKey(t *testing.T) {
536536
if !ok || ref.networkEmojiID() != "paid:product:emoji" {
537537
t.Fatalf("stored reaction = %#v, %v", ref, ok)
538538
}
539+
malformed := &database.Reaction{
540+
EmojiID: "predefined:999",
541+
Metadata: &ReactionMetadata{
542+
MatrixKey: key,
543+
ReactionType: line.ReactionType{PredefinedReactionType: 999},
544+
},
545+
}
546+
mismatched := &database.Reaction{
547+
EmojiID: "paid:different:id",
548+
Metadata: valid.Metadata,
549+
}
550+
ref, ok = storedLineReactionForMatrixKey(key, []*database.Reaction{malformed, mismatched, valid})
551+
if !ok || ref.networkEmojiID() != "paid:product:emoji" {
552+
t.Fatalf("stored reaction after malformed rows = %#v, %v", ref, ok)
553+
}
539554
if _, ok = storedLineReactionForMatrixKey("mxc://line/arbitrary", []*database.Reaction{valid}); ok {
540555
t.Fatal("arbitrary MXC was accepted")
541556
}

0 commit comments

Comments
 (0)