refactor: http request binding (#38971)

Better than before, still not good enough (more work can be done in the
future)

And add the missing error handling in the PrivateContext "bind"
middleware.

By the way, picked some "TrimSpace" changes from "fix: trim whitespace
from SMTP address and port - #38934" (fix #38926)
This commit is contained in:
wxiaoguang
2026-08-19 14:15:42 +08:00
committed by GitHub
parent 6c425fae6e
commit 6904f6480c
21 changed files with 265 additions and 419 deletions
+5 -9
View File
@@ -7,8 +7,6 @@ import (
"testing"
"gitea.dev/modules/glob"
"gitea.com/go-chi/binding"
)
func getGlobPatternErrorString(pattern string) string {
@@ -21,29 +19,27 @@ func getGlobPatternErrorString(pattern string) string {
}
func Test_GlobPatternValidation(t *testing.T) {
AddBindingRules()
globValidationTestCases := []validationTestCase{
{
description: "Empty glob pattern",
data: TestForm{
data: &TestForm{
GlobPattern: "",
},
},
{
description: "Valid glob",
data: TestForm{
data: &TestForm{
GlobPattern: "{master,release*}",
},
},
{
description: "Invalid glob",
data: TestForm{
data: &TestForm{
GlobPattern: "[a-",
},
expectedErrors: binding.Errors{
binding.Error{
expectedErrors: BindingErrors{
BindingError{
FieldNames: []string{"GlobPattern"},
Classification: ErrGlobPattern,
Message: getGlobPatternErrorString("[a-"),