Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid issue info panic #29625

Merged
merged 3 commits into from
Mar 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions models/activities/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,14 @@ func (a *Action) GetCreate() time.Time {
return a.CreatedUnix.AsTime()
}

// GetIssueInfos returns a list of issues associated with
// the action.
// GetIssueInfos returns a list of associated information with the action.
func (a *Action) GetIssueInfos() []string {
return strings.SplitN(a.Content, "|", 3)
// make sure it always returns 3 elements, because there are some access to the a[1] and a[2] without checking the length
ret := strings.SplitN(a.Content, "|", 3)
for len(ret) < 3 {
ret = append(ret, "")
}
Comment on lines +400 to +402
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know in 2 years why that is needed? The whole delimiter concept is fragile because the values are not just numbers but user provided text which can contain the delimiter:

Content: fmt.Sprintf("%d|%s", review.Issue.Index, strings.Split(comm.Content, "\n")[0]),

Content: fmt.Sprintf("%d|%s", pr.Issue.Index, pr.Issue.Title),

Content: fmt.Sprintf("%d|%s|%s", review.Issue.Index, reviewerName, comment.Content),

That field should be json or a struct which can be json serialized by xorm. Here for example it contains json text:
Content: string(data),

Copy link
Contributor Author

@wxiaoguang wxiaoguang Mar 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree with you, but this patch is done intentionally.

  1. The fragile | is as old 2014-07 (8dd07c0 Unknwon on 2014-07-26 at 12:24)
  2. This patch fixes the panic, and is easy to backport

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like don't show the comment which not have enough data.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like don't show the comment which not have enough data.

Then it needs a lot of new {{if}} blocks in the templates. I don't think it's worth to make it that complex.

return ret
}

// GetIssueTitle returns the title of first issue associated with the action.
Expand Down
Loading