From bdf4c6129d68dd95fe81d6ed30c0664669d2eb32 Mon Sep 17 00:00:00 2001 From: Gusted Date: Sun, 20 Mar 2022 20:18:37 +0100 Subject: [PATCH] Fix NPE `/repos/issues/search` when not signed in - Don't panic when on `/repos/issues/search?{created,assigned,mentioned,review_requested}=true` when client didn't pass any authentication. - Resolves #19115 --- routers/api/v1/repo/issue.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 9e550c4c4759e..c96eb348557f2 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -245,18 +245,23 @@ func SearchIssues(ctx *context.APIContext) { UpdatedAfterUnix: since, } + ctxUserID := int64(0) + if ctx.IsSigned { + ctxUserID = ctx.User.ID + } + // Filter for: Created by User, Assigned to User, Mentioning User, Review of User Requested if ctx.FormBool("created") { - issuesOpt.PosterID = ctx.User.ID + issuesOpt.PosterID = ctxUserID } if ctx.FormBool("assigned") { - issuesOpt.AssigneeID = ctx.User.ID + issuesOpt.AssigneeID = ctxUserID } if ctx.FormBool("mentioned") { - issuesOpt.MentionedID = ctx.User.ID + issuesOpt.MentionedID = ctxUserID } if ctx.FormBool("review_requested") { - issuesOpt.ReviewRequestedID = ctx.User.ID + issuesOpt.ReviewRequestedID = ctxUserID } if issues, err = models.Issues(issuesOpt); err != nil {