0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-04-05 12:05:18 +02:00

Address review: guard trimUnclosedCodeBlock and add GetIssueContentBody test

Only call trimUnclosedCodeBlock when truncation actually occurred, and
add unit tests for GetIssueContentBody covering pipe-delimited content.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
silverwind 2026-02-12 21:29:55 +01:00
parent a56cc4da86
commit 95522358b1
No known key found for this signature in database
GPG Key ID: 2E62B41C93869443
2 changed files with 21 additions and 1 deletions

View File

@ -125,6 +125,24 @@ func TestConsistencyUpdateAction(t *testing.T) {
unittest.CheckConsistencyFor(t, &activities_model.Action{})
}
func TestGetIssueContentBody(t *testing.T) {
tests := []struct {
content string
expected string
}{
{content: "1|simple body", expected: "simple body"},
{content: "1|A -->|text| B", expected: "A -->|text| B"},
{content: "1|first|second|third", expected: "first|second|third"},
{content: "1|", expected: ""},
{content: "no-delimiter", expected: ""},
{content: "", expected: ""},
}
for _, test := range tests {
action := &activities_model.Action{Content: test.content}
assert.Equal(t, test.expected, action.GetIssueContentBody(), "content: %q", test.content)
}
}
func TestDeleteIssueActions(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())

View File

@ -152,7 +152,9 @@ func (a *actionNotifier) CreateIssueComment(ctx context.Context, doer *user_mode
truncatedContent = truncatedContent[:lastSpaceIdx] + "…"
}
}
truncatedContent = trimUnclosedCodeBlock(truncatedContent)
if truncatedRight != "" {
truncatedContent = trimUnclosedCodeBlock(truncatedContent)
}
act.Content = fmt.Sprintf("%d|%s", issue.Index, truncatedContent)
if issue.IsPull {