Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions pkg/github/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,10 @@ func AddIssueComment(t translations.TranslationHelperFunc) inventory.ServerTool

var commentResponse *MinimalResponse
if hasBody {
body = sanitize.FilterInvisibleCharacters(body)
if body == "" {
return utils.NewToolResultError("body cannot be empty after removing invisible characters"), nil, nil
}
comment := &github.IssueComment{
Body: github.Ptr(body),
}
Expand Down
26 changes: 26 additions & 0 deletions pkg/github/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4154,6 +4154,32 @@ func TestAddIssueComment(t *testing.T) {
"body": "This is a comment",
},
},
{
name: "strips invisible characters from comment body before posting",
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
PostReposIssuesCommentsByOwnerByRepoByIssueNumber: expect(t, expectations{
path: "/repos/owner/repo/issues/42/comments",
requestBody: map[string]any{"body": "@dependabot rebase"},
}).andThen(mockResponse(t, http.StatusCreated, mockComment)),
}),
requestArgs: map[string]any{
"owner": "owner",
"repo": "repo",
"issue_number": float64(42),
"body": "\u2068@\u2069\u2068d\u2069ependabot rebase",
},
},
{
name: "rejects comment body that is only invisible characters",
requestArgs: map[string]any{
"owner": "owner",
"repo": "repo",
"issue_number": float64(42),
"body": "\u200B\u2068\u2069",
},
expectToolError: true,
expectedToolErrMsg: "body cannot be empty after removing invisible characters",
},
{
name: "successful reaction to issue",
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
Expand Down