fix(forge): refuse a review line number that does not fit an int
Gitea reports a review comment position as a uint64. Past the int range the conversion wrapped negative and would reach a reviewer as a line that cannot exist. Refused instead, with a test that fails when the guard is made inert.
This commit is contained in:
1 parent
51f9f087cf
commit
4481d557a3
2 files changed
+27
No files matched your search
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"math"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -239,6 +240,12 @@ func (c *GiteaClient) ListReviewComments(ctx context.Context, owner, repo string
|
||||
if cm.ID <= sinceID {
|
||||
continue
|
||||
}
|
||||
// LineNum is the forge's uint64. A value past the int range is not a
|
||||
// line this client can name, and wrapping it would put a negative
|
||||
// line number in front of a reviewer.
|
||||
if cm.LineNum > math.MaxInt {
|
||||
return nil, fmt.Errorf("review comment %d on %s/%s#%d has line number %d, which does not fit an int", cm.ID, owner, repo, number, cm.LineNum)
|
||||
}
|
||||
out = append(out, ReviewComment{
|
||||
ID: cm.ID,
|
||||
ReviewID: rv.ID,
|
||||
|
||||
@@ -136,6 +136,26 @@ func TestGiteaListReviewComments(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestGiteaListReviewCommentsRejectsLineNumberPastInt pins the bound on the
|
||||
// forge's line number. Gitea reports position as a uint64; past the int range
|
||||
// the conversion wraps negative and reaches a reviewer as a line that cannot
|
||||
// exist.
|
||||
func TestGiteaListReviewCommentsRejectsLineNumberPastInt(t *testing.T) {
|
||||
c, mux := newTestGiteaClient(t)
|
||||
mux.HandleFunc("GET /api/v1/repos/o/r/pulls/7/reviews", func(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(t, w, []map[string]any{{"id": 3, "state": "COMMENT", "user": map[string]any{"login": "alice"}}})
|
||||
})
|
||||
mux.HandleFunc("GET /api/v1/repos/o/r/pulls/7/reviews/3/comments", func(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(t, w, []map[string]any{
|
||||
{"id": 20, "body": "x", "path": "b.go", "position": uint64(1) << 63, "user": map[string]any{"login": "bob"}},
|
||||
})
|
||||
})
|
||||
|
||||
if _, err := c.ListReviewComments(t.Context(), "o", "r", 7, 0); err == nil {
|
||||
t.Fatal("want an error for a line number that does not fit an int")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGiteaReplyToReview(t *testing.T) {
|
||||
c, mux := newTestGiteaClient(t)
|
||||
var got map[string]any
|
||||
|
||||
Reference in new issue
Block a user