From ef84fda0d430af6cd2b94a29e76f1a52a4b3106e Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Wed, 17 Apr 2019 18:27:55 +0200 Subject: bug: fix a potential crash with malformed data in EditCommentOperation crashed with indexOutOfRange when the target of the op existed but wasn't a CreateOperation or a AddCommentOperation --- bug/op_edit_comment.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'bug/op_edit_comment.go') diff --git a/bug/op_edit_comment.go b/bug/op_edit_comment.go index 49b6a1af..01832959 100644 --- a/bug/op_edit_comment.go +++ b/bug/op_edit_comment.go @@ -36,7 +36,6 @@ func (op *EditCommentOperation) Apply(snapshot *Snapshot) { snapshot.addActor(op.Author) var target TimelineItem - var commentIndex int for i, item := range snapshot.Timeline { h := item.Hash() @@ -45,12 +44,6 @@ func (op *EditCommentOperation) Apply(snapshot *Snapshot) { target = snapshot.Timeline[i] break } - - // Track the index in the []Comment - switch item.(type) { - case *CreateTimelineItem, *AddCommentTimelineItem: - commentIndex++ - } } if target == nil { @@ -75,8 +68,15 @@ func (op *EditCommentOperation) Apply(snapshot *Snapshot) { item.Append(comment) } - snapshot.Comments[commentIndex].Message = op.Message - snapshot.Comments[commentIndex].Files = op.Files + // Updating the corresponding comment + + for i := range snapshot.Comments { + if snapshot.Comments[i].Id() == string(op.Target) { + snapshot.Comments[i].Message = op.Message + snapshot.Comments[i].Files = op.Files + break + } + } } func (op *EditCommentOperation) GetFiles() []git.Hash { -- cgit