fix: issues and pulls route permitted extra characters (#10185)

Fix a issue where the `/{owner}/{repo}/issues` and `/{owner}/{repo}/pulls` routes permitted the addition of extra characters in the URL.

Resolves forgejo/forgejo#9954.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10185
Reviewed-by: Lucas <sclu1034@noreply.codeberg.org>
Reviewed-by: oliverpool <oliverpool@noreply.codeberg.org>
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Adora <me@adora.codes>
Co-committed-by: Adora <me@adora.codes>
This commit is contained in:
Adora 2025-12-10 01:21:38 +01:00 committed by Gusted
parent be43dbfcfb
commit f11d72a8a5
4 changed files with 118 additions and 8 deletions

View file

@ -21,7 +21,7 @@ func TestRoute1(t *testing.T) {
recorder.Body = buff
r := NewRoute()
r.Get("/{username}/{reponame}/{type:issues|pulls}", func(resp http.ResponseWriter, req *http.Request) {
r.Get("/{username}/{reponame}/{type:^(issues|pulls)$}", func(resp http.ResponseWriter, req *http.Request) {
username := chi.URLParam(req, "username")
assert.Equal(t, "gitea", username)
reponame := chi.URLParam(req, "reponame")
@ -46,7 +46,7 @@ func TestRoute2(t *testing.T) {
r := NewRoute()
r.Group("/{username}/{reponame}", func() {
r.Group("", func() {
r.Get("/{type:issues|pulls}", func(resp http.ResponseWriter, req *http.Request) {
r.Get("/{type:^(issues|pulls)$}", func(resp http.ResponseWriter, req *http.Request) {
username := chi.URLParam(req, "username")
assert.Equal(t, "gitea", username)
reponame := chi.URLParam(req, "reponame")
@ -56,7 +56,7 @@ func TestRoute2(t *testing.T) {
hit = 0
})
r.Get("/{type:issues|pulls}/{index}", func(resp http.ResponseWriter, req *http.Request) {
r.Get("/{type:^(issues|pulls)$}/{index}", func(resp http.ResponseWriter, req *http.Request) {
username := chi.URLParam(req, "username")
assert.Equal(t, "gitea", username)
reponame := chi.URLParam(req, "reponame")