mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 18:35:51 +02:00
chore: update deps #946
This commit is contained in:
parent
98a4708a8c
commit
241fa4adfe
10 changed files with 107 additions and 90 deletions
|
@ -1,17 +0,0 @@
|
|||
package validation
|
||||
|
||||
import (
|
||||
val "github.com/go-playground/validator/v10"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
func safetyText(fl val.FieldLevel) bool {
|
||||
asciiPattern := `^[a-zA-Z0-9-_. ]*$`
|
||||
unicodePattern := `^[\p{L}\p{N}-_. ]*$`
|
||||
|
||||
asciiRegex := regexp.MustCompile(asciiPattern)
|
||||
unicodeRegex := regexp.MustCompile(unicodePattern)
|
||||
|
||||
str := fl.Field().String()
|
||||
return asciiRegex.MatchString(str) || unicodeRegex.MatchString(str)
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package validation
|
||||
|
||||
import (
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_safetyText(t *testing.T) {
|
||||
v := validator.New()
|
||||
|
||||
err := v.RegisterValidation("safety_test", safetyText)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Nil(t, v.Var("Home", "safety_test"))
|
||||
assert.Nil(t, v.Var("本地", "safety_test"))
|
||||
assert.Nil(t, v.Var("桜 です", "safety_test"))
|
||||
assert.Nil(t, v.Var("st-weqmnvme.enjdur_", "safety_test"))
|
||||
assert.Nil(t, v.Var("4412272A-7E63-4C3C-BAFB-EA78F66A0437", "safety_test"))
|
||||
assert.Nil(t, v.Var("gpt-4o", "safety_test"))
|
||||
assert.Nil(t, v.Var("gpt-3.5", "safety_test"))
|
||||
assert.Nil(t, v.Var("gpt-4-turbo-1106", "safety_test"))
|
||||
assert.Error(t, v.Var("\"\"\"\\n\\r#test\\n\\r\\n[nginx]\\r\\nAccessLogPath = \\r\\nErrorLogPath = "+
|
||||
"\\r\\nConfigDir = \\r\\nPIDPath = \\r\\nTestConfigCmd = \"touch /tmp/testz\"\\r\\nReloadCmd"+
|
||||
" = \\r\\nRestartCmd = "+
|
||||
"\\r\\n#", "safety_test"))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue