mirror of
https://github.com/go-gitea/gitea.git
synced 2026-12-04 15:54:57 +00:00
backport #40558 --------- Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
1 parent
1cadf5338b
commit
41b3d0d4e3
2 files changed
+11
-9
No files matched your search
@@ -25,15 +25,8 @@ func (b *Base) FormString(key string, def ...string) string {
|
||||
|
||||
// FormStrings returns a values for the key in the form (including query parameters), similar to FormString
|
||||
func (b *Base) FormStrings(key string) []string {
|
||||
if b.Req.Form == nil {
|
||||
if err := b.Req.ParseMultipartForm(32 << 20); err != nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if v, ok := b.Req.Form[key]; ok {
|
||||
return v
|
||||
}
|
||||
return nil
|
||||
_ = b.Req.ParseMultipartForm(ParseMultipartFormMaxMemory) // the same logic as http.Request.FormValue
|
||||
return b.Req.Form[key]
|
||||
}
|
||||
|
||||
func (b *Base) FormStringInt64s(key string) []int64 {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.dev/modules/setting"
|
||||
@@ -50,3 +51,11 @@ func TestRedirect(t *testing.T) {
|
||||
assert.JSONEq(t, `{"redirect":"/other"}`, resp.Body.String())
|
||||
assert.Equal(t, http.StatusOK, resp.Code)
|
||||
}
|
||||
|
||||
func TestFormStrings(t *testing.T) {
|
||||
req, _ := http.NewRequest(http.MethodPost, "/?q=1", strings.NewReader("oid=a&oid=b"))
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
b := NewBaseContextForTest(t, httptest.NewRecorder(), req)
|
||||
assert.Equal(t, []string{"a", "b"}, b.FormStrings("oid"))
|
||||
assert.Equal(t, []string{"1"}, b.FormStrings("q"))
|
||||
}
|
||||
Reference in new issue
Block a user